On line 25 it says myStream >> myNumber where myNumber is initialized to 0 in line 17. I know that it evaluates false if the input is not a number, but I have no idea what the code really says.
Thank you.
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
int main()
{
stringstream ss ;
int bob ;
ss << "5";
ss >> bob;
cout << bob;
return 0;
}
That code wouldn't compile. here's a live version of the stringstream accepting a string literal (number) and then sending it to an integer. Then cout prints it out to the stream.
it says to read an integer from the stream and put it into myNumber.
The expression also tests to ensure that a number was successfully read.
This is made possible by two things:
first, operator>> returns a reference to the stream object;
second, the stream object is boolean comparable, and it is defined to return true if no error has occurred on the stream since the last time the error flag was cleared.