void main() {
ofstream pOut("D:\\Cdxtestaaaa.txt", ios::out | ios::app);//这里如果没有这个文件它是会新建一个
if(pOut.is_open()){
pOut << "hello world\n";
pOut.close();
}
else
{
pOut.close();
}
string strLine;
ifstream pIN("D:\\Cdxtestaaaa.txt", ios::in );
if (pIN.is_open()) {
while (!pIN.eof()) {
getline(pIN, strLine);
cout << strLine << endl;
}
pIN.close();
}
else {
cout << "打开文件失败" << endl;
pIN.close();
}
ifstream pIN2("D:\\Cdxtestbbbbb.txt", ios::in );//这里如果没有这个文件它是会新建一个
if (pIN2.is_open()) {
while (!pIN2.eof()) {
getline(pIN2, strLine);
cout << strLine << endl;
}
pIN2.close();
}
else {
cout << "打开文件失败" << endl;
pIN2.close();
}
system("pause");
}
ifstream ofstrem对文件的操作
最新推荐文章于 2024-03-21 09:10:10 发布