Solved

Update records in file with fstream

Posted on 1998-06-08
1
307 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
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 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.

691 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