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?

  • $\begingroup$ This question isn't really a good match for StackOverflow, since SO normally prefer you to ask much more specific questions. For example, you could try some solution and then ask about a specific implementation issue. Dividing a string into two pieces like that is extremely simple: take a look at str::find and str::substr for one solution. $\endgroup$ – rici Jan 24 '20 at 20:06
  • $\begingroup$ @rici Okay, for substr in this code (apologies for formatting) // 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? $\endgroup$ – JackLalane1 Jan 24 '20 at 20:58
  • $\begingroup$ No, s.substr(pos-1) is the string starting at position pos-1 ("g:cat"), just like s.substr(pos+1) is the substring starting at position pos+1. You need s.substr(0, pos-1). I'm sure your reference material is clear, at least about that :-). (en.cppreference.com/w/cpp/string/basic_string/substr, for example). But this site is not for programming questions, elementary or otherwise. Try Stack Overflow. $\endgroup$ – rici Jan 24 '20 at 21:06
  • $\begingroup$ @rici What is this site for? $\endgroup$ – JackLalane1 Jan 24 '20 at 21:15
  • $\begingroup$ cs.stackexchange.com/help/on-topic $\endgroup$ – rici Jan 24 '20 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.