-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserInfo.cpp
80 lines (69 loc) · 1.58 KB
/
UserInfo.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "UserInfo.h"
#include <iostream>
using namespace std;
UserInfo::UserInfo()
{
Clear();
}
bool UserInfo::Empty() const
{
return un.empty();
}
void UserInfo::Clear()
{
un = "";
pw = "";
name = "";
ismale = false;
year = 0;
month = 0;
date = 0;
}
string UserInfo::KeyWord() const
{
return un;
}
void UserInfo::ShowMsg() const
{
cout << "name: " << name << endl
<< "sex: " << (ismale? "male": "female") << endl
<< "birthday: " << year << '-' << month
<< '-' << date << endl;
}
bool operator== (const UserInfo &u1, const UserInfo &u2)
{
return u1.un == u2.un && u1.pw == u2.pw &&
u1.name == u2.name && u1.ismale == u2.ismale
&& u1.year == u2.year && u1.month == u2.month
&& u1.date == u2.date;
}
bool operator< (const UserInfo &u1, const UserInfo &u2)
{
return u1.un < u2.un;
}
ifstream& operator>> (ifstream &ifs, UserInfo &u)
{
ifs >> u.un >> u.pw >> u.name >> u.ismale
>> u.year >> u.month >> u.date;
return ifs;
}
ofstream& operator<< (ofstream &ofs, const UserInfo &u)
{
ofs << u.un << ' ' << u.pw << ' ' << u.name << ' '
<< (u.ismale? 1: 0) << ' ' << u.year
<< ' ' << u.month << ' ' << u.date << endl;
return ofs;
}
fstream& operator>> (fstream &ifs, UserInfo &u)
{
ifs >> u.un >> u.pw >> u.name >> u.ismale
>> u.year >> u.month >> u.date;
return ifs;
}
fstream& operator<< (fstream &ofs, const UserInfo &u)
{
ofs << u.un << ' ' << u.pw << ' ' << u.name << ' '
<< (u.ismale? 1: 0) << ' ' << u.year
<< ' ' << u.month << ' ' << u.date << endl;
return ofs;
}