-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerator.cc
55 lines (45 loc) · 1.16 KB
/
generator.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
#define COPY_TO_CLIPBOARD
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#ifdef COPY_TO_CLIPBOARD
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#ifdef COPY_TO_CLIPBOARD
namespace utils
{
void copy_to_clipboard(std::string data)
{
auto buf = GlobalAlloc(GMEM_MOVEABLE, data.size());
memcpy(GlobalLock(buf), data.c_str(), data.size());
GlobalUnlock(buf);
OpenClipboard(nullptr);
EmptyClipboard();
SetClipboardData(CF_TEXT, buf);
CloseClipboard();
GlobalFree(buf);
}
}
#endif
int main()
{
std::stringstream ss;
ss << R"(function isOdd(num) {
if (isNaN(num)) {
throw "Input value is not a number!";
} else {)" << std::endl;
for (int i = -INT_MAX; i <= INT_MAX; ++i) {
ss << " if (num === " << i << ")\n"
<< " return " << ((!(i % 2)) ? "false;\n" : "true;\n");
}
ss << " }\n}\n";
#ifdef COPY_TO_CLIPBOARD
utils::copy_to_clipboard(ss.str());
std::cout << "Code content copied to clipboard." << std::endl;
#else
std::cout << ss.str() << std::endl;
#endif
std::getchar();
}