473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

clearing a stringstream

Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();

thanks
Feb 23 '07 #1
5 12155
s5n
On Feb 23, 8:26 pm, Gary Wessle <phd...@yahoo.comwrote:
Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();
For an ostringstream, try os.str("");

Feb 23 '07 #2
Gary Wessle wrote:
Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();
Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

HTH,
- J.
Feb 23 '07 #3
Jacek Dziedzic <ja************************@gmail.comwrites:
Gary Wessle wrote:
Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
Feb 23 '07 #4
Gary Wessle wrote:
Jacek Dziedzic <ja************************@gmail.comwrites:

>>Gary Wessle wrote:
>>>Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
ss.str("");

But I think it's generally better to start with a new stringstream
rather than try to reuse an old one.

Why not post some code?

john
Feb 23 '07 #5
Gary Wessle wrote:
Jacek Dziedzic <ja************************@gmail.comwrites:
>Gary Wessle wrote:
>>Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.


yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
You've been already told: ss.str("")

Don't you have TFM you can R?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 23 '07 #6

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

Similar topics

2
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...
2
by: Woodster | last post by:
I am using std::stringstream to format a string. How can I clear the stringstream variable I am using to "re use" the same variable? Eg: Using std::string std::string buffer; buffer =...
3
by: Mike Chirico | last post by:
Sorry about the newbie question. What's the best way to convert numbers to strings in C++. The following works, but is it better than using the sprintf() "old C" way of converting? #include...
1
by: KidLogik | last post by:
Hello! I am using std::stringstream && std::string to parse a text file -> std::ifstream in; std::string s; std::streamstring ss; int n; I grab each line like so -> std::getline(in,s);
5
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
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...
4
by: news.eircom.net | last post by:
Hello, How do you clear the contents of an ostringstream object? I've included some example code so you can see what I mean. t.i.a. Craig H. #include <iostream>
1
by: Gary Wessle | last post by:
hi I have a design problem with this code, it is suppose to take a space delimited data file file_info x( f ); //f is a text file provided below and return the column of choice vector<stringbb...
9
by: martinezfive | last post by:
Hi, I feel no doubt some documentation contains my answer, so bare with me. Given the following: #inclde <stdio.h> #include <sstream> void f() { std::stringstream a("Hello World!\n");
7
by: Ziyan | last post by:
I am writing a C/C++ program that runs in background (Linux). Therefore, normally no output would be written into standard output. However, sometimes I want to have debug message collected and sent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.