I think you need to loop the string. Find punctuation operators and then create a substring. Then push the substring back in a list or vector and then output it.
getline(infile, str);
vector<string> strings;
int pos = 0;
for(int i = 0; i < str.length(); ++i)
{
if( (str[i] == '!') || (... all the punctuation operators)
{
strings.push_back(str.substr(pos, (i - (int)pos));
pos = i + 1;
}
}
for(int i = 0; i < (int)strings.size(); ++i)
{
cout << strings[i] << endl;
}
I'm not sure if the substring method is correct. I didn't test this code. You can mess around with it.
The substr prototype is this: substr( starting_position, number_of_characters_to_extract );
That is not what it is really but.. that's how it's used.