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

Related questions

1 answer 149 views
1 answer 153 views
1 answer 141 views
1 answer 136 views
1 answer 145 views
...