473,322 Members | 1,610 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,322 software developers and data experts.

Clearing std::stringstream

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 = "value1" + " : " + "value2";
buffer = "value3" + " : " + "value4";

Gives values of
value1 : value2
value3 : value4

The = operator for std::string overwrites the preivous contents of the
string, but I have been unable to locate a similar thing for
std:stringstream

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?

Thanks in advance

Jul 19 '05 #1
2 7455
Woodster wrote:
....

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer.str( "" ); // set the contents to the empty string.
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?


use the .str( string ) method ... it should be an FAQ.

Jul 19 '05 #2
I'm not sure, but you can try

buffer.flush();

Catalin

"Woodster" <mi****@127.0.0.1> wrote in message
news:MP************************@news.westnet.com.a u...
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 = "value1" + " : " + "value2";
buffer = "value3" + " : " + "value4";

Gives values of
value1 : value2
value3 : value4

The = operator for std::string overwrites the preivous contents of the
string, but I have been unable to locate a similar thing for
std:stringstream

using std::stringstream

std::stringstream buffer;

buffer << "value1" << " : " << "value2";
buffer << "value3" << " : " << "value4";

Gives values of
value1 : value2
value1 : value2value3 : value4

Which is not the desired result. How should I go about clearing the
buffer of a std::stringstream?

Thanks in advance

Jul 19 '05 #3

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

Similar topics

6
by: Giampiero Gabbiani | last post by:
Is it possible to reset a std::stringstream in order to reuse it once more? I tried with flush() method without any success... Thanks in advance Giampiero
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: Marcin Kalicinski | last post by:
Is there a vectorstream class that implements the functionality similar to std::stringstream but with std::vector, not std::string? cheers, Marcin
5
by: ma740988 | last post by:
Consider: #include <iostream> #include <sstream> #include <string> int main ( ) { { double pi = 3.141592653589793238; std::stringstream a;
1
by: magix | last post by:
I got this reply in my previous post a month ago: May I know, how can I automatically create the folder if it doesn't exist ? In previous reply, it said: -------------------------...
2
by: akitoto | last post by:
Hi there, I am using the std::stringstream to create a byte array in memory. But it is not working properly. Can anyone help me? Code: #include <vector> #include <sstream> #include...
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...
7
by: Grey Alien | last post by:
Does *ANYONE* in here know how I may parse the various date/time 'elements' from a string?. The input string has the ff format: 'YYYY-MM-DD HH:MM:SS AM'
3
by: Rune Allnor | last post by:
Hi all. I am trying to use std::stringstream to validate input from a file. The strategy is to read a line from the file into a std::string and feed this std::string to an object which breaks it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.