-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (73 loc) · 1.48 KB
/
main.cpp
File metadata and controls
88 lines (73 loc) · 1.48 KB
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
import std;
using namespace std;
void error(string s)
{
throw runtime_error{s};
}
void error(string s1, string s2)
{
throw runtime_error{ s1 + s2 };
}
void edit_time(string& s)
{
int T = 0;
T = static_cast<int>(s.find('T'));
string hour = s.substr(T + 1, 2);
stringstream hourss{ hour };
int int_hour = 0;
hourss >> int_hour;
if (!hourss)
cerr << "error!" << '\n';
int_hour += 8;
string new_hour = to_string(int_hour);
if (int_hour < 10)
new_hour.insert(0, "0");
s.replace(T + 1, 2, new_hour);
const int Z = static_cast<int>(s.find('Z'));
if (Z == string::npos)
error("the file has been converted.");
s.erase(Z, 1);
//cout << s << '\n';
}
int main()
{
try
{
cout << "Please enter the name of file which you want to convert: " << "\n";
string filename;
cin >> filename;
ifstream ifs{ filename };
vector<string> readings;
if (!ifs)
error("can't open file: ", filename);
string format;
getline(ifs, format);
for (string x; getline(ifs, x); )
{
edit_time(x);
readings.push_back(x);
}
//if (!ifs)
// error("ifs is fail");
ofstream ofs{ filename };
for (const string& x : readings)
ofs << x << '\n';
if (!ofs)
error("ofs is fail");
cout << "The UTC in the file has been converted to UTC+8." << '\n';
system("pause");
return 0;
}
catch (exception& e)
{
cerr << "error: " << e.what() << '\n';
system("pause");
return 1;
}
catch (...)
{
cerr << "Oops: unknown exception!" << '\n';
system("pause");
return 2;
}
}