65,210
社区成员
发帖
与我相关
我的任务
分享
class Data{
private:
int hight;
int width;
public:
Data(int hight, int width):hight(hight),width(width){}
void get()const{cout<<"high: "<<hight<<" width: "<<width<<endl;}
friend ofstream &operator<<(ofstream &os, const Data& d){os<<d.hight<<d.width; return os;}
};
int main()
{
ofstream os("D:\\data.txt",ios::out);
vector<Data> vec;
int i;
for(i=0; i<10; ++i) vec.push_back(Data(i,i));
for(i=0; i<10; ++i) os<<vec[i];
os.close();
return 0;
}