-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI O with Multiple Objects.cpp
More file actions
63 lines (46 loc) · 916 Bytes
/
Copy pathI O with Multiple Objects.cpp
File metadata and controls
63 lines (46 loc) · 916 Bytes
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
58
59
60
61
62
63
#include <iostream>
#include <fstream>
using namespace std;
//
class person
{
protected:
char name[40];
int age;
public:
void getData()
{
cout << "\n Enter name: "; cin >> name;
cout << " Enter age: "; cin >> age;
}
void showData()
{
cout << "\nName: " << name;
cout << "\nAge: " << age;
}
};
int main()
{
setlocale(LC_ALL, "italian");
char ch;
person pers;
fstream file;
file.open("MultipleObj.TXT", ios::app | ios::in | ios::binary);
do
{
cout << "Enter person's data: ";
pers.getData();
file.write(reinterpret_cast<char*> (&pers), sizeof(pers));
cout << "Enter another person (y/n)? ";
cin >> ch;
} while (ch == 'y');
file.seekg(0);
file.read( reinterpret_cast<char*> (&pers), sizeof(pers));
while (!file.eof())
{
cout << "\nPerson: ";
pers.showData();
file.read(reinterpret_cast<char*> (&pers), sizeof(pers));
}
return 0;
}