File Handling in C++ :: Dev c++ 5.4.2
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "What is your name? ";
cin >> name;
ofstream out( "inputfile.txt",ios::ate );
if(out.is_open())
out << " My Name Is: " << name << "!" << endl;
else cout<<"Unable to Open File ";
string line;
fstream in ("inputfile.txt");
if(in.is_open()){
while(getline(in,line) ){
in>>line;
cout<<line;
}
}
else{ cout<<"\nfile not open"; }
out.close();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "What is your name? ";
cin >> name;
ofstream out( "inputfile.txt",ios::ate );
if(out.is_open())
out << " My Name Is: " << name << "!" << endl;
else cout<<"Unable to Open File ";
string line;
fstream in ("inputfile.txt");
if(in.is_open()){
while(getline(in,line) ){
in>>line;
cout<<line;
}
}
else{ cout<<"\nfile not open"; }
out.close();
return 0;
}
Post a Comment