istringstream reusing initializing

Started by
3 comments, last by Zahlman 16 years, 8 months ago
linky Well it was asked long ago and it was unanswered. So what i want to do is : std::istringstream istr; //get a string from an edit box istr.str(myString); istr>>someinteger; //get another string from another editbox istr.str(myString); istr>>anotherInt; I couldn't find a way to do this other than using different istringstreams and creating them with the constructor like std::istringstream istr(myString); Any help?
Advertisement
Add a call to istr.clear().
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Or just use boost::lexical_cast which avoids this kind of error.
Quote:Original post by dalleboy
Add a call to istr.clear().


Bingo. There isn't a problem with your call to str(string). The internal string object is being updated, but the error bits aren't being reset. clear() does just that.
Quote:Original post by Black Knight
I couldn't find a way to do this other than using different istringstreams and creating them with the constructor like std::istringstream istr(myString);


Well, is it really a problem to do that? Usually this kind of thing happens in a loop, so you can just put this construction at the top of the loop.

This topic is closed to new replies.

Advertisement