Cách xử lý file đơn giản trong C++
#include<iostream>
#include<fstream>
using namespace std;
class fileProcess
{
public:
void input()
{
//Phan 1: Write data to file
//Tao doi tuong de mo file
ofstream fo;
fo.open("D:\\data.txt");
//Kiem tra mo file co thanh cong?
if(fo.is_open())
{
fo<<"Hello CMU_TPM5!"<<endl;
fo<<"How are you? How have your family been? I hope you are well!"<<endl;
fo.close();
}
else
cout<<"File not found!"<<endl;
}
void output()
{
//Phan 2: Read data from file
ifstream fi;
fi.open("D:\\data.txt");
string str="";
if(fi.is_open())
{
while(!fi.eof())
{
getline(fi,str);
cout<<str<<endl;
}
fi.close();
}
else
cout<<"File error!"<<endl;
}
};
int main()
{
fileProcess f;
f.input();
f.output();
return 0;
}
Trương Đình Huy
- So sánh hệ thống tài khoản kế toán trong Thông tư 99/2025/TT-BTC và Thông tư 200/2014/TT-BTC
- Common Pitfalls in TOEIC Preparation and How Strategic Learning Improves Test Performance
- Singapore’s First Multi-Storey 3D-Printed House
- 3D Concrete printing Technology
- Giới thiệu 8 đặc điểm của High Performance Team

