-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileio3.cpp
More file actions
57 lines (54 loc) · 1.04 KB
/
fileio3.cpp
File metadata and controls
57 lines (54 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Program to show file input output
#include<fstream>
#include<iostream>
using namespace std;
class animal
{
int itsWeight;
int itsAge;
public:
animal(int,int);
~animal();
int getitsWeight();
void setitsWeight();
int getitsAge();
void setitsAge();
};
animal::animal(int itsWeight,int itsAge)
{
this->itsWeight=itsWeight;
this->itsAge=itsAge;
}
animal::~animal()
{
}
int animal::getitsWeight()
{
return itsWeight;
}
void animal::setitsWeight()
{
cout<<"Enter weight"<<endl;
cin>>itsWeight;
}
int animal::getitsAge()
{
return itsAge;
}
void animal::setitsAge()
{
cout<<"Enter age"<<endl;
cin>>itsAge;
}
int main()
{
animal buck(1,1),buk2(0,0);
ofstream fout("Animal.txt",ios::binary);
fout.write((char*) &buck,sizeof buck);
fout.close();
ifstream fin("Animal.txt",ios::binary);
fin.read((char*)&buk2,sizeof buk2);
cout<<buk2.getitsWeight();
cout<<buk2.getitsAge();
fin.close();
}