流类库11

#include<iostream>
#include<fstream>
using namespace std;
class Dog{
public:
int gdoga()
{
return a;
}
int gdogw()
{
return w;
}
void setdog(int x,int y)
{
a=x;
w=y;
}
private:
int a,w;
};
int main()
{
int v1,v2;
Dog dog1;
dog1.setdog(5,10);
ofstream
outFile("outfile.txt",ios::out);
outFile<<dog1.gdoga()<<" "<<dog1.gdogw();
outFile.close();
Dog dog2;
ifstream
inFile("outfile.txt",ios::in);
inFile>>v1;
inFile.seekg(1,ios::cur);
inFile>>v2;
dog2.setdog(v1,v2);
outFile.close();
cout<<"Weight:"<<dog2.gdoga()<<" ";
cout<<"Age:"<<dog1.gdogw();
return 0;
}

posted @ 2023-05-17 19:59  不会JAVA的小袁  阅读(9)  评论(0编辑  收藏  举报