stringstream parser;
parser << 5;
short top = 0;
parser >> top;
parser.str(""); //HERE I'M RESETTING parser
parser << 6; //DOESN'T PUT 6 INTO parser
short bottom = 0;
parser >> bottom;
Why doesn’t it work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Typically to ‘reset’ a stringstream you need to both reset the underlying sequence to an empty string with
strand to clear any fail and eof flags withclear.Typically what happens is that the first
>>reaches the end of the string and sets the eof bit, although it successfully parses the first short. Operations on the stream after this immediately fail because the stream’s eof bit is still set.