Solved

reset iostream

Posted on 1997-04-25
1
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

632 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