fork(14) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. vector<string> csvColumn;
  8. int main() {
  9. string line;
  10. while (std::getline(cin, line)) {
  11. const char *mystart=line.c_str();
  12. bool instring{false};
  13. for (const char* p=mystart; *p; p++) {
  14. if (*p=='"')
  15. instring = !instring;
  16. else if (*p==',' && !instring) {
  17. csvColumn.push_back(string(mystart,p-mystart));
  18. mystart=p+1;
  19. }
  20. }
  21. csvColumn.push_back(string(mystart));
  22. }
  23. for (auto &x: csvColumn)
  24. cout<<x<<endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3468KB
stdin
"Primary, Secondary, Third", "Primary", , "Secondary", 18, 4, 0, 0, 0
Line2,
"Line3,ok","yes,I'm happy
stdout
"Primary, Secondary, Third"
 "Primary"
 
 "Secondary"
 18
 4
 0
 0
 0
Line2

"Line3,ok"
"yes,I'm happy