The clear() member function is inherited from ios and is used to clear the error state of the stream, e.g. if a file stream has the error state set to eofbit (end-of-file), then calling clear() will set the error state back to goodbit (no error). For clearing the contents of a stringstream , using: m. str("");
myStream. rdbuf()->in_avail() can be used to get the count of available characters ready to be read in from a stringstream , you can use that to check if your stringstream is "empty." I'm assuming you're not actually trying to check for the value null .
strstream has been deprecated since C++98, std::stringstream and boost::iostreams::array are the recommended replacements.
You can't return a stream from a function by value, because that implies you'd have to copy the stream.
I've always done:
s.clear();//clear any bits set
s.str(std::string());
@litb gets into more detail about how to seekp to the start of the stream combined with std::ends you can keep your allocated size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With