fork download
  1. #include <fstream>
  2. #include <optional>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. #include "/Users/me/Applications/fmt/include/fmt/core.h"
  8.  
  9.  
  10. constexpr std::size_t minfields{33};
  11.  
  12. std::optional<std::vector<std::string>> splitStr(const std::string &line,
  13. const char delimiter = ',')
  14. {
  15. std::vector<std::string> splitLine;
  16. splitLine.reserve(minfields);
  17. std::istringstream ss(line);
  18. std::string buf;
  19. unsigned field{0};
  20. while (std::getline(ss, buf, delimiter)) {
  21. splitLine.push_back(buf);
  22. if (field == 3 && buf[0] != 'E' && buf[0] != 'T') {
  23. return std::nullopt;
  24. }
  25. ++field;
  26. }
  27. if (splitLine.size() < minfields)
  28. return std::nullopt;
  29. return splitLine;
  30. }
  31.  
  32. void copy_selective(std::istream &in, FILE *out)
  33. {
  34. std::string line;
  35. while (std::getline(in, line)) {
  36. auto split = splitStr(line, ';');
  37. if (split) {
  38. const std::vector<std::string> &vec = split.value();
  39. fmt::print(out,
  40. "{},{},{},{},{},{},{},{},{},{},{}\n",
  41. vec[0],
  42. vec[1],
  43. vec[3],
  44. vec[4],
  45. vec[5],
  46. vec[6],
  47. vec[10],
  48. vec[9],
  49. vec[11],
  50. vec[7],
  51. vec[32]);
  52. }
  53. }
  54. }
  55.  
  56. int main(int argc, char *argv[])
  57. {
  58. if (argc >= 3) {
  59. std::ifstream inFile(argv[1]);
  60. FILE *outFile{fopen(argv[2], "w")};
  61. copy_selective(inFile, outFile);
  62. }
  63. }
  64.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:10: fatal error: /Users/me/Applications/fmt/include/fmt/core.h: No such file or directory
 #include "/Users/me/Applications/fmt/include/fmt/core.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty