How to parse a comma separated string in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

int main() {
    std::string s = "a,b,4,c++,9,java";

    std::stringstream ss(s);
 
    while (ss.good()) {
        std::string subs;
        getline(ss, subs, ',');
        std::cout << subs << '\n';
    }
}




/*
run:

a
b
4
c++
9
java

*/

 



answered Feb 14, 2022 by avibootz
...