-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
86 lines (60 loc) · 1.72 KB
/
main.cc
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
#include <fstream>
#include <iostream>
#include <regex>
#include <cstdlib>
static std::string code = R"TAG(#include <fstream>
#include <iostream>
#include <regex>
#include <cstdlib>
// CODE_PLACEHOLDER
int main() {
std::string const cxx_file_name = "/tmp/x.cc";
std::string const run_file_name = "/tmp/x.run";
{
std::regex const re_code_placeholder{"// CODE_PLACEHOLDER"};
std::string const cp_inject =
std::string("static std::string code = R\"TAG(") + code +
")TAG\";";
code = std::regex_replace(
code,
re_code_placeholder,
cp_inject,
std::regex_constants::format_first_only
);
}
{
std::ofstream file(cxx_file_name);
file << code;
}
std::string const cmd_compile =
"g++ " + cxx_file_name + " -o " + run_file_name;
std::system(cmd_compile.c_str());
std::system(run_file_name.c_str());
return 0;
}
)TAG";
int main() {
std::string const cxx_file_name = "/tmp/x.cc";
std::string const run_file_name = "/tmp/x.run";
{
std::regex const re_code_placeholder{"// CODE_PLACEHOLDER"};
std::string const cp_inject =
std::string("static std::string code = R\"TAG(") + code +
")TAG\";";
code = std::regex_replace(
code,
re_code_placeholder,
cp_inject,
std::regex_constants::format_first_only
);
}
{
std::ofstream file(cxx_file_name);
file << code;
}
std::string const cmd_compile =
"g++ " + cxx_file_name + " -o " + run_file_name;
std::system(cmd_compile.c_str());
std::system(run_file_name.c_str());
return 0;
}