By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Of stream manipulators, stringstreams and character sets

P: n/a
1) Are the manipulators like std::endl and std::ends independent of
character set. That is, can I use the same manipulators in both the
following cases:

a)
<code>
std::basic_stringstream<char> strm;

strm<<"What goes up ... !"<<std::endl<<"You know the
rest!"<<std::ends;
</code>

b)
<code>
std::basic_stringstream<wchar_t> wstrm;

wstrm<<L"What goes up ... !"<<std::endl<<L"You know the
rest!"<<std::ends;
</code>

(Please overlook any windows specifics, see the problem below and
don't redirect me to ms.microsoft....)

2) Is it possible to clear a stringstream after writing to it and then
using it again? I mean I want this:

<code>

std::basic_stringstream<char> strm;

strm<<"What goes up ... !"<<std::endl<<"You know the
rest!"<<std::ends;

/*
... do something so that strm has no characters and we can write to
it (may
be remove std::ends if it prevents that)
*/

strm<<"Here is a new string ... with no strings attached before
it"<<std::endl;

</code>
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 14 Nov 2003 11:41:51 -0800, ga***********@yahoo.com (Andy) wrote:
1) Are the manipulators like std::endl and std::ends independent of
character set. That is, can I use the same manipulators in both the
following cases:

a)
<code>
std::basic_stringstream<char> strm;

strm<<"What goes up ... !"<<std::endl<<"You know the
rest!"<<std::ends;
</code>

b)
<code>
std::basic_stringstream<wchar_t> wstrm;

wstrm<<L"What goes up ... !"<<std::endl<<L"You know the
rest!"<<std::ends;
</code>

(Please overlook any windows specifics, see the problem below and
don't redirect me to ms.microsoft....)
Yes, endl is templated on character type and traits type, so the above
is fine.

2) Is it possible to clear a stringstream after writing to it and then
using it again? I mean I want this:

<code>

std::basic_stringstream<char> strm;

strm<<"What goes up ... !"<<std::endl<<"You know the
rest!"<<std::ends;
There's no good reason to write std::ends to a stringstream. Doing so
just adds a \0 character, and is only useful for null terminated
strings, not for std::string. Perhaps you are confusing stringstream
with strstream?
/*
... do something so that strm has no characters and we can write to
it (may
be remove std::ends if it prevents that)
*/


strm.str(std::string()); //clear held string
strm.clear(); //clear error flags if any

Tom
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.