Skip to main content
gamedev.net
🔒 Locked

istringstream reusing initializing

Started by Black Knight Aug 13, 2007 at 5:52 AM 3 replies 2.9k views
Original Post
Black Knight
Black Knight
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?
SiCrane
SiCrane
Or just use boost::lexical_cast which avoids this kind of error.
EnergyTurtle
EnergyTurtle
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.
Zahlman
Zahlman
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.