-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPostInfo.cpp
101 lines (88 loc) · 2.02 KB
/
PostInfo.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
94
95
96
97
98
99
100
101
#include "PostInfo.h"
#include "Utility.h"
#include <iostream>
#include <time.h>
using namespace std;
//#define _DEBUG
PostInfo::PostInfo()
{
ptime = time(0);
}
string PostInfo::KeyWord() const
{
return un;
}
void PostInfo::ShowMsg() const
{
cout << un << ": " << content
<< " " << UnixTimeToLocal(ptime) << endl;
}
bool operator== (const PostInfo &p1, const PostInfo &p2)
{
return p1.un == p2.un && p1.content == p2.content &&
p1.ptime == p2.ptime;
}
bool operator< (const PostInfo &p1, const PostInfo &p2)
{
return p1.ptime < p2.ptime;
}
ifstream& operator>> (ifstream &ifs, PostInfo &p)
{
string line;
getline(ifs, line);
if(!ifs) return ifs;
int delim1 = line.find(' ');
p.ptime = stoi(line.substr(0, delim1));
#ifdef _DEBUG
cout << "DEBUG: " << line.substr(0, delim1) << endl;
#endif
delim1++;
int delim2 = line.find(' ', delim1);
p.un = line.substr(delim1, delim2 - delim1);
#ifdef _DEBUG
cout << "DEBUG: " << p.un << endl;
#endif
delim2++;
p.content = line.substr(delim2, line.size() - delim2);
#ifdef _DEBUG
cout << "DEBUG: " << p.content << endl;
#endif
//ifs >> p.ptime >> p.un >> p.content;
//return ifs;
}
ofstream& operator<< (ofstream &ofs, const PostInfo &p)
{
ofs << p.ptime << ' ' << p.un
<< ' ' << p.content << endl;
return ofs;
}
fstream& operator>> (fstream &ifs, PostInfo &p)
{
string line;
getline(ifs, line);
if(!ifs) return ifs;
int delim1 = line.find(' ');
p.ptime = stoi(line.substr(0, delim1));
#ifdef _DEBUG
cout << "DEBUG: " << line.substr(0, delim1) << endl;
#endif
delim1++;
int delim2 = line.find(' ', delim1);
p.un = line.substr(delim1, delim2 - delim1);
#ifdef _DEBUG
cout << "DEBUG: " << p.un << endl;
#endif
delim2++;
p.content = line.substr(delim2, line.size() - delim2);
#ifdef _DEBUG
cout << "DEBUG: " << p.content << endl;
#endif
//ifs >> p.ptime >> p.un >> p.content;
//return ifs;
}
fstream& operator<< (fstream &ofs, const PostInfo &p)
{
ofs << p.ptime << ' ' << p.un
<< ' ' << p.content << endl;
return ofs;
}