Solved

reset iostream

Posted on 1997-04-25
1
358 Views
Last Modified: 2006-11-17
Can anyone tell me how I can reset an ostrstream.

char buf[512];
ostrstream os(buf,512);

//... put stuff into os

cout << os.rdbuf();

//... at this point I would like to reset
//... to the beginning of the stream in order
//... to use it again.

Thanks
Carson
0
Comment
Question by:carsonw
1 Comment
 

Accepted Solution

by:
Sigma031497 earned 50 total points
ID: 1162990
To set the read pointer, use seekg(pos, ios::beg), where pos is the offset from the start of the file.

To set the write pointer, use seekp(pos, ios::beg).

Hence in your case you want to do do

os.seekp(0, ios::beg);

Keep in mind, that the file will not be modified, just the write pointer. Any new data you write will overwrite the previous data, but data which you will not overwrite will remain. If you want to clear the file of all data, the only way you can do this is

os.close();
os.open(name, ios::out | ios::trunc);

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question