473,511 Members | 16,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to flush the ostringstream buffer?

Hi,

I have a quetion about to refresh the ostringstream buffer: like this.

ostringstream buffer;

buffer << 245;
// then the buffer.str() = "245";

......
//next I want using this buffer again but I don't need the content of buffer
before, so
buffer.flush()
buffer << 456;
//here I hope I can get "456" from buffer.str()

but the buffer still is 245456, seem the buffer.flush not take function?

why?
who can help me?

Thanks adanveced,

Bill
Nov 17 '05 #1
2 4028
flush() doesn't clear the stream; it writes any pending [buffered] data
(useful for file streams which hold written data in memory buffer and only
actually write to file when buffer gets full or someone calls flush).
Try seekp(0) to set insert position back to start, thereby emptying string?

Bill

"Bill Sun" <su******@hotpop.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have a quetion about to refresh the ostringstream buffer: like this.

ostringstream buffer;

buffer << 245;
// then the buffer.str() = "245";

.....
//next I want using this buffer again but I don't need the content of buffer before, so
buffer.flush()
buffer << 456;
//here I hope I can get "456" from buffer.str()

but the buffer still is 245456, seem the buffer.flush not take function?

why?
who can help me?

Thanks adanveced,

Bill

Nov 17 '05 #2

"Bill Sun" <su******@hotpop.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a quetion about to refresh the ostringstream buffer: like this.
ostringstream buffer;

buffer << 245;
// then the buffer.str() = "245";

.....
//next I want using this buffer again but I don't need the content of buffer before, so
buffer.flush()
buffer << 456;
//here I hope I can get "456" from buffer.str()


You should use

buffer.str("");

to reset the contents of the buffer to an empty string.

Jonathan
Nov 17 '05 #3

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

Similar topics

5
743
by: Als | last post by:
What's the meaning of "freeze" as member of ostringstream class? Is it needed always to call freeze() at the disposal of an ostringstream object? Is it also needed before disposing an istringsteam...
5
2347
by: Simon Pryor | last post by:
I am having some strange problems using std::ostringstream. The simple stuff works okay, but trying to use: std::ostringstream::str(const std::string&) or:...
3
5587
by: Mathieu Malaterre | last post by:
Hello, I am trying to write this simple code: std::ostringstream s; s << 1024; std::cout << s.str() << std::endl; s.str(""); // <- problem s << 512; std::cout << s.str() << std::endl;
4
7427
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>
3
11089
by: Kyle Kolander | last post by:
I posted this in response to a previous thread but have not gotten any replies back... Hopefully someone has an answer? From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears...
5
2489
by: Luiz Vianna | last post by:
Guys, I need to send some info to my client while I'm processing some stuff. The flow will be something like : -process -response -process -response .... I imagine to use response.flush...
1
5466
by: nitroamos | last post by:
i'm working on improving the IO for the software project i'm working on to do two extra things. first, i'm going to add HDF5 functionality, and second, add the ability to write binary output. the...
3
4056
by: Generic Usenet Account | last post by:
With the deprecated ostrstream class, when the constructor is invoked without arguments, memory is dynamically allocated. In that case the onus on freeing the memory lies with the user. Typically...
1
8086
by: schoedl | last post by:
Hello, we often compose strings via a ostringstream and then create a string from it. What is the rationale of not being able to use string in place of a ostringstream, so I could write ...
0
7138
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
7355
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
7423
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
7081
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
7510
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
5668
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,...
0
4737
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
3225
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
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.