visual studio 2019 read and write text file c 2b 2b

Solutions on MaxInterview for visual studio 2019 read and write text file c 2b 2b by the best coders in the world

showing results for - "visual studio 2019 read and write text file c 2b 2b"
Lilly
06 Apr 2017
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}