文件流
ofstream,由ostream派生而来,用于写文件
ifstream,由istream派生而来,用于读文件
fstream,由iostream派生而来,用于读写文件
#include <cassert>
#include<iostream>
#include <fstream>
using namespace std;
int main(void)
{
ofstream fout;
fout.open("test.txt");
if (fout.is_open())
{
cout << "succeed" << endl;
}
else
{
cout << "failed" << endl;
}
if (fout.good())//流状态是否正常
{
cout << "succeed" << endl;
}
else
{
cout << "failed" << endl;
}
if (fout)
{
cout << "succeed" << endl;
}
else
{
cout << "failed" << endl;
}
if (!fout)
{
cout << "failed" << endl;
}
else
{
cout << "succeed" << endl;
}
assert(fout);
fout.close();
return 0;
}