Thao tác trên file với C++
#include<iostream>
#include<fstream>
using namespace std;
class fileProcess
{
public:
string line;
void output()
{
ofstream fo;
fo.open("D:\\test.txt");
if(fo.is_open())
{
fo<<"Vu Nhu Can\n";
fo<<"Dong Nhu Khoi\n";
fo.close();
}
else
cout<<"File not found....!";
}
void input()
{
ifstream fi;
fi.open("D:\\test.txt");
if(fi.is_open())
{
while(!fi.eof())
{
getline(fi,line);
cout<<line<<endl;
}
}
else
cout<<"File not found!!!!"<<endl;
}
};
int main()
{
fileProcess f;
f.output();
f.input();
return 0;
}
Trương Đình Huy

