views:

4363

answers:

4

I'm looking for a good tutorial on how to do string manipulation with stringstream in C++. Currently, I'm doing the following:

double d = 7.234;
stringstream out;
out.width(8);
out.precision(6);
out << fixed << d;

I like this link for a list of what options are available, but I learn best from examples and would like to see some more examples with predicted outputs of the various options so that I am not just guessing to get my desired behavior.

+4  A: 

If you want a good book, I would start with The C++ Standard Library by Josuttis and STL Tutorial and Reference Guide by Musser, Derge, and Saini. Both contain pretty nice descriptions of iostreams. The online reference that you are using is as good as any for online usage.

D.Shawley
+4  A: 

The best and most detailed (far more detailed than Josuttis) book on stream I/O, including stringstreams, is Standard C++ IOStreams & Locales by Langer and Kreft.

anon
It's sitting on my desk about 40cm from my right arm - excellent book.
Richard Corden
Nice... just added this one to the ol' Amazon Wish List. Thanks.
D.Shawley
+1  A: 

Here a link that serves as a topic introduction on stringstream with usage. In regards to an on-line tutorial I believe the general consensus is to refer to texts that will undoubtedly be referenced in this thread a million times over as demonstrated by a web search of the same topic.

C Johnson