-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYuFile.cpp
93 lines (81 loc) · 2.17 KB
/
YuFile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
#include"YuFile.h"
YuFile::YuFile()
{
ifstream ifs(YU_FILE, ios::in);
string studenID;
string studenName;
string chooseDate;
string chooseTime;
string chooseRoom;
string status;
this->m_Size = 0;
while (ifs >> studenID && ifs >> studenName && ifs >> chooseDate && ifs >> chooseTime && ifs >> chooseRoom && ifs >> status)
{
string key;
string stay;
map<string, string>m;
int Pos = studenID.find(":");
if (Pos != -1)
{
key = studenID.substr(0, Pos);
stay = studenID.substr(Pos + 1, studenID.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
Pos = studenName.find(":");
if (Pos != -1)
{
key = studenName.substr(0, Pos);
stay = studenName.substr(Pos + 1, studenName.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
Pos = chooseDate.find(":");
if (Pos != -1)
{
key = chooseDate.substr(0, Pos);
stay = chooseDate.substr(Pos + 1, chooseDate.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
Pos = chooseTime.find(":");
if (Pos != -1)
{
key = chooseTime.substr(0, Pos);
stay = chooseTime.substr(Pos + 1, chooseTime.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
Pos = chooseRoom.find(":");
if (Pos != -1)
{
key = chooseRoom.substr(0, Pos);
stay = chooseRoom.substr(Pos + 1, chooseRoom.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
Pos = status.find(":");
if (Pos != -1)
{
key = status.substr(0, Pos);
stay = status.substr(Pos + 1, status.size() - Pos - 1);
m.insert(make_pair(key, stay));
}
YuMap.insert(make_pair(this->m_Size, m));
this->m_Size++;
}
ifs.close();
}
void YuFile::updateFile()
{
if (this->m_Size == 0)
{
return;
}
ofstream ofs(YU_FILE, ios::out | ios::trunc);
for (int i = 0; i < this->m_Size; i++)
{
ofs << "studenID:" << YuMap[i]["studenID"]<<" ";
ofs << "studenName:" << YuMap[i]["studenName"] << " ";
ofs << "chooseDate:" << YuMap[i]["chooseDate"] << " ";
ofs << "chooseTime:" << YuMap[i]["chooseTime"] << " ";
ofs << "chooseRoom:" << YuMap[i]["chooseRoom"] << " ";
ofs << "status:" << YuMap[i]["status"] << endl;
}
ofs.close();
}