Saturday, 17 August 2013

Why doesn't loop terminate even after 'ss.fail()' is true (Here 'ss' is a stringstream object)?

Why doesn't loop terminate even after 'ss.fail()' is true (Here 'ss' is a
stringstream object)?

The following code:
int main() {
stringstream ss;
string str;
str = "999:97 42:22 44:102300";
ss << str;
char ch;
int temp, temp1;
while (1) {
if (ss.fail()) {
break;
}
ss >> temp >> ch >> temp1;
cout << temp << ":" << temp1 << endl;
}
return 0;
}
This gives the following output:
999:97
42:22
44:102300
44:102300
Here's a link as well: http://ideone.com/cC75Sk
I just wanted to know, why does the code doesn't end after the break
statement ?

No comments:

Post a Comment