Re: c++ fstream writing to existing file
From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 07/24/04
- Next message: JKop: "Re: returning static arrays"
- Previous message: Victor Bazarov: "Re: How to reuse a friend operator?"
- In reply to: Mahesha: "c++ fstream writing to existing file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Jul 2004 10:39:42 -0700
ycmahesh@hotmail.com (Mahesha) wrote in message news:<3d09d707.0407231701.3d611ce5@posting.google.com>...
> Hello,
> I'm new to C++ and I have requirement to open a existing text file in
> write mode and write 2 new lines of text in the beginning of the file.
> I'm working with fstream standard library.
> If someone could direct me to a sample code to do this that would be
> really helpful.
Most file systems will only let you add to the end of a file. The
usual way to handle this is:
1. copy current file contents to a temporary file.
2. rewind the original file.
3. write your two lines to the file.
4. copy the contents from the temporary file back to the original.
--
Later,
Jerry.
The universe is a figment of its own imagination.
- Next message: JKop: "Re: returning static arrays"
- Previous message: Victor Bazarov: "Re: How to reuse a friend operator?"
- In reply to: Mahesha: "c++ fstream writing to existing file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|