Appending to a File and using Fstream class for Read and Write

This video tutorial explains how to append to a file in c++ programming and also explains how to open the file using fstream object for read and write.
You are gonna learn how to open a file for appending, which file opening mode to use to append to the file, how to open file for both read and write operation in detail with an example.

source code for this tutorial

#include <iostream>
#include <fstream>
using namespace std;

int main()
fstream file("anil.txt",ios::in | ios::out | ios::app);
    cout << "error while opening the file"<<endl;
cout <<"file opened succesfully"<<endl;
cout <<"writing to the file"<<endl;

file << "learning lad rocks"<<endl;

cout <<"reading from the file"<<endl;
string line;
    cout << line <<endl;


    return 0;

Back To Top