clearing a stringstream
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
nevermind figured it out.. doh!
std::stringstream stream;
stream.str("");
"That''s not a bug, it''s a feature!"
--me
std::stringstream stream;
stream.str("");
"That''s not a bug, it''s a feature!"
--me
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 ]
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]
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]
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]
what about...?
std::stringstream stream;
... do stuff
stream = std::stringstream();
[edited by - petewood on April 1, 2003 3:24:13 AM]
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 ]
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 ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement