Need reference for stringstream

C

clb

I am trying to use stringstreams and my book doesn't cover the included
methods. For example, if I init a istringstream on a string and suck all
the data out, then put more stuff into the string, how do I reset the
ISS to see the new data? Does this make sense?
 
S

sebor

I am trying to use stringstreams and my book doesn't cover the included
methods. For example, if I init a istringstream on a string and suck all
the data out, then put more stuff into the string, how do I reset the
ISS to see the new data? Does this make sense?

You can start with the Apapche C++ Standard Library online
documentation,
the chapter on string streams in the User's Guide:
http://incubator.apache.org/stdcxx/doc/stdlibug/31.html
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

I am trying to use stringstreams and my book doesn't cover the included
methods. For example, if I init a istringstream on a string and suck all
the data out, then put more stuff into the string, how do I reset the
ISS to see the new data? Does this make sense?

You have to put the new content into the stringstream, depending on
your needs it might be as simple as to use the << operator to output
the string to the stringstream. Notice that the string you specified
in the ctor is not used as buffer for the stringstream, only
initialization. Check this site out for more information:
http://www.cplusplus.com/reference/iostream/stringstream/stringstream.html
 
B

BobR

clb said:
I am trying to use stringstreams and my book doesn't cover the included
methods. For example, if I init a istringstream on a string and suck all
the data out, then put more stuff into the string, how do I reset the
ISS to see the new data? Does this make sense?

First, use 'MySs.clear();' to reset any 'fail flags' on the stream.
Then you can empty the stream by doing:
MySs.str("");

.... or, re-use it:
MySs.str("Hello world!");

Actually, you don't 'suck all the data out'. Try an experiment; set your
istringstream, 'suck all the data out', then try:
MySs.clear();
MySs.seekg(0); // assumes an std::stringstream
..... then try 'reading' it again.
What happens?

[ correctios, as always, are welcome. ]
 
B

BobR

Erik Wikström wrote in message...
/* """
I am trying to use stringstreams and my book doesn't cover the included
methods. For example, if I init a istringstream on a string and suck all
the data out, then put more stuff into the string, how do I reset the
ISS to see the new data? Does this make sense?

You have to put the new content into the stringstream, depending on
your needs it might be as simple as to use the << operator to output
the string to the stringstream. Notice that the string you specified
in the ctor is not used as buffer for the stringstream, only
initialization. Check this site out for more information:
http://www.cplusplus.com/reference/iostream/stringstream/stringstream.html
- - Erik Wikström
""" */

Hi Erik,

<cough><choke> a '<<' on an std::istringstream'? <G>
(the OP mentioned 'istringstream', so thought I'd poke a little fun.)

Actually, I'm only (re)posting to mention to the OP that Dinkumware has some
documentation too. [ I forgot to put that in my other post]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top