Brand new to c++ and im having difficulty splitting on a string. I have seen some examples of this on stack overflow, but I could not get the samples to work when looping in the for loop.
Essentially I have an array of strings that looks like.
const string userData[] =
{"A1,John,Smith,smithJ@mail.com,42",
"B2,Jane,Doe,jd@gmailcom,121,2",
"C3,Mickey,Mouse,mouseman@mail.com,20"
};
Below is the closest I have gotten to a solution myself
string s;
vector<istringstream> streamV;
vector<string> stringV;
for(const auto& str : userData)
{
istringstream nasa { str };
getline(nasa, s, ',');
stringV.push_back(s);
}
cout << stringV[0] << endl;
cout << stringV[1] << endl;
Output
A1
B1
Desired goal: I want to have each comma separated value added to a vector. Then, call out class constructors doing some inline typecasting for the last value from a string to an int.
Edit1 I understand my question is similar to The most elegant way to iterate the words of a string The main difference was that the solutions provided did not work well with a comma separated list, and as well iterating through an array/vector.