Quote:Original post by snake5
istringstream makes useless copies of the string, allocates memory often when it's not necessary.
I really doubt that a half-decent implementation would do that.
Quote:And it is not so simple to use it.
I'd suggest using C string functions here because they also help to develop bug seeking skills. ^_^
int num1, num2;double decimal_number;std::string a_string; //parse a string containing two ints, a floating-point number, and a stringa_stringstream >> num1 >> num2 >> decimal_number >> a_string;
You just have to keep in mind how it parses whitespace. Save your bug-seeking skills for where they're needed.Actually, I usually use plain stringstream, which does input and output. It makes it a little easier. This page is a good reference. For stuff more complicated than that, you'll want regexes or a parsing framework. Boost.Regex and Boost.Spirit can be pretty nice. Or, depending on what you're using it for, an existing data format with pre-built parsers might be more convenient, like XML or JSON.