Write a program to writing in to a text file, read from a text file and display
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
string text="";
fstream textFile;
cout<<"Enter text: ";
getline(cin,text);
textFile.open("textFile.txt", ios::out);
textFile << text;
textFile.close();
string line;
text="";
ifstream infile;
infile.open ("textFile.txt");
while(!infile.eof())
{
getline(infile,line);
text+=line+"\n";
}
cout<<"\n\Text from the file: \n\n";
cout<<text;
infile.close();
system("pause");
return 0;
}
Comments
Leave a comment