?
Solved

Update records in file with fstream

Posted on 1998-06-08
1
Medium Priority
?
308 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 80 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

Independent Software Vendors: 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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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 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…

770 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