If your strings are going to contain possible whitespace and you want to use ',' as a delimiter, then you can use the getline function. As an example, if your file looks like this:
Code:
hello there, my friend, 46
I'm doing fine, thank you, 16
Then something like this should work:
Code:
while (!file.eof())
{
getline(file,str1,',');
getline(file,str2,',');
file >> int1;
file.ignore(80,'\n'); // 80 is somewhat arbitrary but should be sufficient
cout << "str1: " << str1
<< ", str2: " << str2
<< ", int1: " << int1 << endl;
}
Output should be:
Code:
str1: hello there, str2: my friend, int1: 46
str1: I'm doing fine, str2: thank you, int1: 16