473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange behavior of stringstream

In case A(see below), ss.clear() doesn't work and have no error
message. cout<<ss.str() shows "xcv".

In case B ss.clear() works normally and cout<<ss.str() shows
nothing.

Can anyone tell me why ? Thanks.

Case A:

stringstream ss;
ss<<"xcv";
{
ss.clear();
cout<<ss.str();
}

---------------------------
Case B:

{
stringstream ss;
ss<<"xcv";
ss.clear();
cout<<ss.str();

}

Nov 21 '06 #1
2 1396
* li********@gmail.com:
In case A(see below), ss.clear() doesn't work and have no error
message. cout<<ss.str() shows "xcv".

In case B ss.clear() works normally and cout<<ss.str() shows
nothing.

Can anyone tell me why ? Thanks.

Case A:

stringstream ss;
ss<<"xcv";
{
ss.clear();
cout<<ss.str();
}

---------------------------
Case B:

{
stringstream ss;
ss<<"xcv";
ss.clear();
cout<<ss.str();

}
There should be no behavioral difference.

'clear' doesn't clear the contents of the stream.

It's inherited from std::ios, and clears the state flags.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 21 '06 #2
Thanks Steinbach .

But under the VS2005 they do have behavioral difference.

Now I use ss.str(""); instead of ss.clear() to solve the problem.
Alf P. Steinbach ¼g¹D¡G

>
There should be no behavioral difference.

'clear' doesn't clear the contents of the stream.

It's inherited from std::ios, and clears the state flags.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5842
by: Bill Beacom | last post by:
Hi all, I am trying to use stringstream to assemble a text message from a set of user-defined objects that have the insertion operator overloaded. It seems to be putting them into the...
5
10830
by: cherico | last post by:
I'd like to read stings from cin and put them in stringstream. I use a string object as an intermediate "container" to store data from cin and then put them in stringstream. stringstream ss ;...
5
817
by: William Payne | last post by:
How do you get rid the contents in a std::stringstream? I'm using one in a for loop to format some status messages which I print to the screen. The stringstream member function clear() only clears...
6
3236
by: Tom | last post by:
I try to write a simple tcp based job queue server. It's purpose is to get commands from a client and store them in a queue (STL). The server has a thread which checks periodically the queue,...
33
1022
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
24
2278
by: asdf | last post by:
I got a warning from the following statement: fprintf(point_file, "CONTOUR\nCLOSE\n%d\n", curve.size()); warning: format '%d' expects type 'int', but argument 3 has type 'size_t' should I...
0
1810
by: rbottone | last post by:
Since the strstream classes will be deprecated in the future, I have been looking for an alternative to this class for performing binary I/O. stringstream indicates that you can use...
10
2592
by: vigacmoe | last post by:
I was trying to cast some strings to integers with stringstream, then this strange problem poped up. Here is my test code: stringstream conv; string from; int to; from = "1"; conv << from;
2
2201
by: drusakov | last post by:
consider the following piece of code, compiled with g++ 3.4 and stlport 5.1 on Linux 64 bit (problem persists in 32 bit too) std::stringstream ss; int ii = 123; ss << "test1";...
0
7076
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
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
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...
0
7453
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...
1
5005
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
4670
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...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
377
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.