-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
40 lines (38 loc) · 872 Bytes
/
main.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
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <set>
#include "process.cpp"
using namespace std;
int main(int argc, char *argv[])
{
try
{
if (argc > 2)
{
return query(argv[1], argv[2]);
}
else if (argc < 2)
{
return process(cin);
}
// ifstream是输入文件流(input file stream)的简称, std::ifstream
// 离开作用域后,fh文件将被析构器自动关闭
ifstream fh(argv[1]); // 打开一个文件
if (!fh)
{
// open file failed
perror(argv[1]);
return 1;
}
char buf[81920];
fh.rdbuf()->pubsetbuf(buf, sizeof(buf));
return process(fh);
}
catch (char *e)
{
fprintf(stderr, "%s\n", e);
return 2;
}
}