fork(23) download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. int main() {
  7. std::stringstream ss;
  8. ss << "\"Primary, Secondary, Third\", \"Primary\", , \"Secondary\", 18, 4, 0, 0, 0";
  9.  
  10. while (ss >> std::ws) {
  11. std::string csvElement;
  12.  
  13. if (ss.peek() == '"') {
  14. ss >> std::quoted(csvElement);
  15. std::string discard;
  16. std::getline(ss, discard, ',');
  17. }
  18. else {
  19. std::getline(ss, csvElement, ',');
  20. }
  21.  
  22. std::cout << csvElement << "\n";
  23. }
  24. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Primary, Secondary, Third
Primary

Secondary
18
4
0
0
0