Answer to Question #214033 in C++ for Hemambar

Question #214033

Write a program to writing in to a text file, read from a text file and display


1
Expert's answer
2021-07-16T01:04:27-0400
#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;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS