I am given two files one with the name of person and the location that they are from (Evan Lloyd|Brownsville) and one with the name and salary (Evan Lloyd|58697) (the line number that you find the employee on in the first file is not necessarily the line number that find the employee on in the second). The user inputs a location (whole or part). For example if they input "ville" or "Ville" it should include all of the employees in Brownsville, Clarksville, Greenville, etc. I am supposed to join the the name and salary and return them if they are in the city searched for i.e. "ville" or "Ville." I am attempting to use a vector for both of the files vector(name, address) and vector(name, salary) and later return a vector of a string and tuple (address, (name, salary)) as my output. I don't know how to tokenize the string for example "Evan Lloyd|Brownsville" into the substrings "Evan Lloyd" and "Brownsville" separately (without the |) and save them separately so that I can push both strings into my vector(name, address). How would I tokenize the strings that way or should I try something else entirely?
Asked
Active
Viewed 34 times
0
str::find
andstr::substr
for one solution. – rici Jan 24 '20 at 20:06// Take any string string s = "dog:cat"; // Find position of ':' using find() int pos = s.find(":");
// Copy substring after pos string sub = s.substr(pos + 1); //returns cat would string sub = s.substr(pos-1); return dog? – JackLalane1 Jan 24 '20 at 20:58
s.substr(pos-1)
is the string starting at positionpos-1
("g:cat"), just likes.substr(pos+1)
is the substring starting at positionpos+1
. You needs.substr(0, pos-1)
. I'm sure your reference material is clear, at least about that :-). (https://en.cppreference.com/w/cpp/string/basic_string/substr, for example). But this site is not for programming questions, elementary or otherwise. Try [so]. – rici Jan 24 '20 at 21:06