how many ways of updating a file do we have in c++?

If u want to update or append to a text file using fopen function call, u can use both "a" and "a+" access modes. For binary an additional "b" character has to be included in the mode string (i.e ab and ab+ or a+b).

Mode a : Appends to a file. Writing operations appends data at the end of the file.

Mode a+ : Opens a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. U can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file.

Note : In both the cases the file is created if it does not exist.

Cheers,

If u want to update or append to a text file using fopen function call, u can use both "a" and "a+" access modes. For binary an additional "b" character has to be included in the mode string (i.e ab and ab+ or a+b).

Mode a : Appends to a file. Writing operations appends data at the end of the file.

Mode a+ : Opens a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. U can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file.

Note : In both the cases the file is created if it does not exist.

This is C FILE *
In C++ we have better fstream Objects having modes:

ios::in
ios::out
ios::in | ios::out
ios::ate
ios::app
ios::binary //Can be used with all above
This article has been dead for over six months. Start a new discussion instead.