1#include <fstream>
2#include <memory>
3
4std::string getOutputName(int n)
5{
6  char buf[256];
7  snprintf(buf, sizeof buf, "input-%03d", n);
8  printf("%s\n", buf);
9  return buf;
10}
11
12int main(int argc, char* argv[])
13{
14  std::ifstream in(argv[1]);
15  std::string line;
16  int count = 0;
17  int size = 0;
18  int64_t total = 0;
19  std::unique_ptr<std::ofstream> out(new std::ofstream(getOutputName(count)));
20  while (getline(in, line))
21  {
22    line.append("\n");
23    size += line.size();
24    total += size;
25    *out << line;
26    if (size >= 1000'000'000)
27    {
28      ++count;
29      out.reset(new std::ofstream(getOutputName(count)));
30      size = 0;
31    }
32  }
33  // out.reset();
34}
35
36
37