Write a program in C++ to open and read the contents of the Text1.txt using the file stream class. Close the file and again open to update the contents of given file Text1.txt. Text1.txt : I am enjoying learning OOPS concepts After update Text1.txt: I am enjoying learning OOPS concepts Now learnt C++; Java is my next target.
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
string line1, line2, line3,tString;
fstream fileName;
ofstream outputfile;
fileName.open("Text1.txt",ios::out);
if(!fileName){
cout<<"There is some error in creating the file"<<endl;
return 0;
}
cout<<"file created successfully"<<endl;
fileName<<"I am enjoying learning OOPS concepts"<<endl;
fileName.close();
return 0;
}
Comments
Leave a comment