1 | #include <cstdio> |
---|---|
2 | #include <fstream> |
3 | #include <iostream> |
4 | #include <stdlib.h> |
5 | #include <string> |
6 | |
7 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
9 | #include <fcntl.h> |
10 | |
11 | int main(int argc, char* argv[]) { |
12 | if (argc != 3) { |
13 | fprintf(stderr, "Requires two arguments: file copied from, file copied to.\n"); |
14 | exit(-1); |
15 | } |
16 | |
17 | std::string from_filename{ argv[1] }; |
18 | std::string to_filename{ argv[2] }; |
19 | |
20 | std::ifstream from_file{ from_filename }; |
21 | std::ofstream to_file{ to_filename }; |
22 | |
23 | const std::string prefix{ "usertable user"}; |
24 | |
25 | while (!from_file.eof()) { |
26 | char buffer[256]; |
27 | from_file.getline(buffer, sizeof(buffer)); |
28 | std::string line{ buffer }; |
29 | std::string::size_type pos = line.find(prefix); |
30 | if (pos == std::string::npos) { |
31 | continue; |
32 | } |
33 | line = line.substr(pos + prefix.size()); |
34 | uint64_t key = stol(line); |
35 | |
36 | to_file.write(reinterpret_cast<char*>(&key), sizeof(key)); |
37 | } |
38 | } |
39 |