   std::stringstream - more problems
  So, I have been doing something like: std::stringstream Stream;std::string String("moo cow");Stream << String;Sadly, it seems like the Stream object will only input "moo"... In other words, it will only input a word at once. I would like it to input the whole string at once... And for output operations, output the whole buffer into an std::string at once... This is very important since it is for a templated shell variable system... The only prartical solution otherwise is to directly inherit a string variable class from my base variable class, but that defeats the purpose of templates, its a dirty solution.I have been looking around, but there are very few pages that talk about std::stringstream (and show useful information). Does anybody know a solution to this?   Looking for a serious game project?  www.xgameproject.com[edited by - Max_Payne on February 16, 2004 3:06:40 PM]
  stringstream has no problem with having more than one word at a time inserted into it. And for dumping it to a string, just use the str() member function.EDIT: I'm guessing that what you're REALLY running into is that, like all streams, it extracts one word at a time. So input is not actually the problem, but rather output. #include <iostream>#include <string>#include <sstream>using namespace std;int main(){    string foo = "hello world";    string foo2;    stringstream bar;    bar << foo;    bar << "!\n";    foo2 = bar.str();    cout << foo2;} "Sneftel is correct, if rather vulgar." --Flarelocke   [edited by - sneftel on February 16, 2004 3:15:35 PM];  Are you sure that it only inputs the first word? If so you may have a broken STL implementation. That code runs fine on both compilers I tried it on (MSVC .NET 2003, gcc 3.3.1) ;  You need to write your data in a form that''s delineable.Consider:std::string a( "this is a string" );std::string b( "this is another string" );myStream << a;myStream << b;  myStream will now contain "this is a stringthis is another string" without any means of knowing where the boundaries are. Scanning a word, by default, uses whitespace for delineation.Thus, you need to do one of two things:1) write the number of characters in the string, followed by a whitespace, followed by the string. When reading in, read the number of characters, skip the whitespace, and read that many characters into a string.2) write the string in a quoted format, and parse it (character by character) when reading back in.