I want to be able to parse a string such as:
inputStr = "abc 12 aa 4 34 2 3 40 3 4 2 cda t 4 car 3"
Into separate vectors (a string vector and integer vector) such that:
strVec = {"abc", "aa", "cda", "t", "car"};
intVec = {12, 4, 34, 2, 3, 40, 3, 4, 2, 4, 3};
What is a good method to do this? I'm somewhat familiar with stringstream and was wondering whether it's possible to do something like this:
std::string str;
int integer;
std::vector<int> intVec;
std::vector<std::string> strVec;
std::istringstream iss(inputStr);
while (!iss.eof()) {
if (iss >> integer) {
intVec.push_back(integer);
} else if (iss >> str) {
strVec.push_back(str);
}
}
I have attempted something to that effect, but the program seems to enter a halt of sorts (?). Any advice is much appreciated!