Solved

reset iostream

Posted on 1997-04-25
1
356 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ - Convert a wString to char * 9 501
C++ dll will not run on machine without VS installed 10 80
Getting IP address 8 71
computer science syllabus 3 70
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

929 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

14 Experts available now in Live!

Get 1:1 Help Now