Solved

Update records in file with fstream

Posted on 1998-06-08
1
296 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

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

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.

910 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

22 Experts available now in Live!

Get 1:1 Help Now