Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ChaosEngine

clearing a stringstream

This topic is 5559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is there anyway to clear the buffer of a stringstream? I''m using one to hold a description string that''s writen to in a serialise method, but I want to be able to change it after a certain point. any ideas? "That''s not a bug, it''s a feature!" --me

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by ph33r
I think clear or flush would have worked too.


stringstream::clear() doesn''t clear the buffer, but the stream flags (eof, fail, bad). As such, it is required too.


std::stringstream stream;
stream.clear();
stream.str("");




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
ph33r, already tried those and they didn't work.

thanks, fruny. forgot about the flags!

"That's not a bug, it's a feature!"
--me

[edited by - ChaosEngine on April 1, 2003 2:29:22 AM]

Share this post


Link to post
Share on other sites
edit: just ignore me - see fruny below

what about...?

std::stringstream stream;
... do stuff
stream = std::stringstream();

[edited by - petewood on April 1, 2003 3:24:13 AM]

Share this post


Link to post
Share on other sites
Standard iostreams are not assignable. If they were, your method would reset all the stream''s state (format option, locale, user data...) not just clear the buffer.

Swapping the rdbuf() with a local one isn''t a very good idea either (lifetime issue), nor is dynamic allocation (ha!)


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!