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