65,211
社区成员
发帖
与我相关
我的任务
分享
// ostream 有很多,不单是cout 比如下面的ofstream
#include <iostream>
#include <fstream>
using namespace std;
class A {
public :
A() : data(0)
{
}
int data;
};
ostream& operator<< (ostream& out, const A& a)
{
out<<a.data;
return out;
}
int main()
{
ofstream ofile("a.txt");
A a;
a.data = 100;
ofile<<a;
ofile.close();
return 0;
}