Answer to Question #272894 in C++ for Amit

Question #272894

 Write 2 program to create a file. input user defined data entered from keyboard and write to the file. Read the contents of the file in reverse order and store to another file.


1
Expert's answer
2021-11-29T18:45:37-0500
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
	fstream file("text.txt",ios::out);
	cout<<"Enter a string\n";
	string text;
	cin>>text;
	file<<text<<"\n";
	file.close();
	
	
	fstream new_file("text.txt",ios::in);
	string str[100];
	int i= 0;
	while(!new_file.eof()){
		new_file>>str[i];
		i++;
	}
	int n = i -1;
	for(int x=n; x>=0; x--){
		cout<<str[x]<<endl;
	}
}

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