EDIT 1
I forgot to say that the string has to be taken from cin
I have a string like "Hi; my;; name is Andrea; and I like C++".
I want to create a stringstream initialized with that string and get everything before the last ;.
This is what I've tried:
string ex("Hi; my;; name is Andrea;; and I like C++"), text, final_text;
stringstream loop_stream(ex);
int findComma = loop_stream.str().find(';');
do {
getline(loop_stream, text, ';');
loop_stream.ignore(1);
final_text += text;
loop_stream << loop_stream.rdbuf();
findComma = loop_stream.str().find(';');
while (findComma == 1) {
loop_stream.ignore(1);
}
findComma = loop_stream.str().find(';');
}
while (findComma != string::npos);
cout << "-" << final_text << "-" << endl;
but it doesn't work at all... I would like the output to be:
-Hi; my;; name is Andrea-