Solved

Update records in file with fstream

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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.

730 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