473,508 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Of stream manipulators, stringstreams and character sets

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
1 4264
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3330
by: rwawryk | last post by:
Hi, Does anybody know how to implement parametrized stream operator (such as setw, setfill)? I need to put into the stream variable of type char* without terminating NULL. It would be great if I...
7
14358
by: Stewart Gordon | last post by:
Using g++ 3.1, Mac OS X. I'm doing something trying to involve a null output stream, i.e. a stream that just discards what goes into it. The idea is that it gives a simple way of producing...
10
1708
by: Kyle Kolander | last post by:
Got a strange bug going on here... // proper includes and additional code here int x = 2552123; cout << x; This results in output like this: 2,552,123 Same behavior with stringstreams. ...
7
6747
by: Riku Jarvinen | last post by:
Hello everyone, I have a logging class which writes program outputs to the logfile. The class works fine as long as only C++ native data types are considered. The problem is that I have a...
5
2164
by: Riku Jarvinen | last post by:
Hi everyone, I asked another question regarding this same subject about a week ago. See thread: ...
5
2053
cheeseboy
by: cheeseboy | last post by:
Hi, I have made a stream that outputs to a window (with Windows API). With the following code I can print some text to a window: stream<<"some text\r\n"; but what I want to be able to do is...
3
25181
by: JackC | last post by:
Hi, How do i use stringstreams getline function to extract lines from an existing string? Say i have: string strlist = "line1\r\nLine2\r\nLine3\r\n"; I want to extract each line out into a...
33
2017
by: john | last post by:
I am reading TC++PL3 and in "21.3.3 Stream State", 4 member functions returning bool are mentioned: template <class Ch, class Tr= char_traits<Ch class basic_ios: public ios_base { public: //...
2
1516
by: Steven Woody | last post by:
Here is the code, uint16_t n1, n2; ... std::ostringstream os; os << "(" << std::hex << std::setw(4) << std::setfill('0') << n1 << "," << std::setw(4) << std::setfill('0') << n2 << ")"; ...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.