#include<bits/stdc++.h>
using namespace std;
class Dog{
private:
int weight;
int old;
public:
Dog(int a,int b):weight(a),old(b){};
int Weight(){
return weight;
}
int Old()
{
return old;
}
~Dog(){};
};
int main()
{Dog dog1(5,10);
fstream out1;
out1.open("dog1.1.txt",ios::binary|ios::out);
out1<<"dog: "<<endl<<"体重:"<<dog1.Weight()<<endl<<"年龄:"<<dog1.Old()<<endl;
fstream in;
fstream out2;
in.open("dog1.1.txt",ios::binary|ios::in);
out2.open("dog2.2.txt",ios::binary|ios::out);
out2<<"dog2:"<<endl;
char n;
while(!in.eof())
{
in.get(n);
out2.put(n);
}
return 0;
}
文件打开方式均以二进制方式打开。
标签:out2,old,weight,16,int,输入输出,ios,Dog,pta From: https://www.cnblogs.com/djcf/p/17406618.html