Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating files

Status
Not open for further replies.

hurstbs

Programmer
Oct 18, 2002
8
US
I can read from a file, but if I want to change just one line in the file, how would I go about doing that? For example, I have a text file that lists usernames and passwords.

George
Zebra
Jack
precious

I know how to use <fstream> to read this information and save it to variables, but if the user wants to change the password or the username, what do I need to do to change just one line in the file? Any help would be appreciated.
 
You can use the seekoff() function to go to a specific position in a file, then just overwrite your text.
 
>> then just overwrite your text.

um that will only work if you are writing the EXACT number of bytes at that location.

The standard way of handling that is to write the remaining portion of the file from the location of the change to the end.

good luck
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top