1#include <iostream>
2#include <fstream>
3#include <string>
4using namespace std;
5int main(){
6 fstream newfile;
7 newfile.open("tpoint.txt",ios::out); // open a file to perform write operation using file object
8 if(newfile.is_open()) //checking whether the file is open
9 {
10 newfile<<"Tutorials point \n"; //inserting text
11 newfile.close(); //close the file object
12 }
13 newfile.open("tpoint.txt",ios::in); //open a file to perform read operation using file object
14 if (newfile.is_open()){ //checking whether the file is open
15 string tp;
16 while(getline(newfile, tp)){ //read data from file object and put it into string.
17 cout << tp << "\n"; //print the data of the string
18 }
19 newfile.close(); //close the file object.
20 }
21}