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.
#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;
}
}
Comments
Leave a comment