Solved

Update records in file with fstream

Posted on 1998-06-08
1
293 Views
Last Modified: 2010-04-01
How can i update the records in file using c++ fstream
classes ( seekp and tellp ) ???? or is there a diffrent
method of doing this ???
0
Comment
Question by:sector
1 Comment
 
LVL 11

Accepted Solution

by:
alexo earned 20 total points
ID: 1165345
The istream class has the seekg() and tellg() methods for positioning the read pointer.
The ostream class has the seekp() and tellp() methods for positioning the write pointer.

Say you have these definitions:

    struct Record { ... };

    Record patish;
    fstream f("laflaf");

Say you want to read record #17:

    f.seekg(17 * sizeof Record, ios::beg) >> patish;

Say you want to write it into record #23:

    f.seekp(23 * sizeof Record, ios::beg) << patish;

tellg() and tellp() return the current read/write position which you can use in a single-argument versions of seekg() and seekp().

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…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

21 Experts available now in Live!

Get 1:1 Help Now