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
- Thư viện numpy trong python (1)
- Định Hướng Phát Triển Trong Khoa Học Máy Tính & CNTT: Lựa Chọn Nghiên Cứu (Research) Hay Ứng Dụng (Application)?
- Đo Đạc Khoảng Cách và Diện Tích Trực Tuyến Từ Dữ Liệu Quét 3D
- Navigating Global Opportunities: An Introduction to the LanguageCert Test
- Terra Cotta Workshop: Xưởng gốm bên sông Thu Bồn giành chiến thắng tại RIBA International Awards for Excellence 2026

