//C++ program to write and read text in/from file.
using namespace std;
fstream file; //object of fstream class
//opening file "sample.txt" in out(write) mode
cout<<"Error in creating file!!!"<<endl;
cout<<"File created successfully."<<endl;
//write text into file
//closing the file
//again open file in read mode
cout<<"Error in opening file!!!"<<endl;
//read untill end of file is not found.
char ch; //to read single character
cout<<"File content: ";
file>>ch; //read single character from file
file.close(); //close file
File created successfully.
File content: ABCD.
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.