Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reset iostream

Posted on 1997-04-25
1
Medium Priority
?
365 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 100 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

721 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