Solved

reset iostream

Posted on 1997-04-25
1
355 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now