Skip to main content
gamedev.net
🔒 Locked

strstream question

Started by grulim 5 replies 1k views
Original Post
grulim
grulim
Hi anyone, I've code like this:

strstream req1;

req1 << "some text" << std::ends;
someFunction(req1.str());

strstream req2;
req1 << "some other text" << std::ends;
someFunction(req2.str());
i don't like using 2 strstream and i can't figure out how to empty req1. Some idea ? or am i doing something evil ;) ?
quant
quant
strstreams are deprecated in standard c++, they have been replaced with stringstreams.

#include<sstream>std::stringstream ss;ss << "Hello world";somefunc(ss.str().c_str());ss.str(std::string(""));ss << "Another hello world";somefunc(ss.str().c_str());

-keyboard
jollyjeffers
jollyjeffers
I cant directly help you, but...

isn't the <strstream> header deprecated now? seem to remember seeing that in MSVC, and 3.x GCC's

Try <sstream> - std::istringstream and std::ostringstream (iirc off the top of my head).

I think the two I just mentioned have methods to empty the buffers.

hth
Jack

EDIT: Quant beat me by 28 seconds! But I'm sure theres a better way to reset the stream than he suggests.. but I suppose it still works.
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Pipo DeClown
Pipo DeClown
Quote:
Original post by grulim
Hi anyone,

I've code like this:
strstream req1;req1 << "some text" << std::ends;someFunction(req1.str());strstream req2;req1 << "some other text" << std::ends;someFunction(req2.str());


i don't like using 2 strstream and i can't figure out how to empty req1. Some idea ? or am i doing something evil ;) ?


strstream::clear()?? Does it exist?
Skizz
Skizz
Well, with strstreams you need to do the following:
strstream s;s << some_stuff;char *c_string = s.str ();// do stuff with c_string// the .str () function above freezes the stream.// Not sure of the exact reason for this (memory allocation probably)// unfreeze the streams.freeze (false);// set write position back to the starts.seekp (0);

Skizz
grulim
grulim
Quote:
Original post by Skizz
Well, with strstreams you need to do the following:
strstream s;s << some_stuff;char *c_string = s.str ();// do stuff with c_string// the .str () function above freezes the stream.// Not sure of the exact reason for this (memory allocation probably)// unfreeze the streams.freeze (false);// set write position back to the starts.seekp (0);

Skizz

I try this solution, but does'nt seems to work :(
Anyways, i'll switch to stringstream.
Thank you, guy :)
quant
quant
Nothing says thanks quite like a good rating ;) [/hint]
-keyboard

Topic Locked

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

Sign in to reply to this topic.