-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.cpp
44 lines (40 loc) · 953 Bytes
/
score.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
#include <iostream>
#include <fstream>
#include "score.h"
using namespace std;
list<pair<int, int>>* score::get(){
ifstream fin;
fin.open(user_name+"s", ios::in);
if(!fin)
return NULL;
list<pair<int, int>> *re = new list<pair<int,int>>;
int eid, escore;
while(fin >> eid >> escore)
re->push_back(pair<int, int>(eid, escore));
fin.close();
return re;
}
void score::write(int eid, int escore){
ifstream fin;
fin.open(user_name+"s", ios::in);
if(!fin){
ofstream ff(user_name+"s", ios::out);
ff.close();
}
ofstream fout(user_name+"s", ios::out|ios::app|ios::ate);
fout << eid << " " << escore << "\n";
fout.close();
}
bool score::is_taken(int eid){
ifstream fin;
fin.open(user_name+"s", ios::in);
if(!fin)
return false;
int idd, score;
while(fin >> idd){
fin >> score;
if(idd == eid)
return true;
}
return false;
}