dimanche 28 mars 2021

How do I parse comma-delimited string in C++ with some elements being quoted with commas?

I have a comma-delimited string that I want to store in a string vector. The string and vectors are:

string s = "1, 10, 'abc', 'test, 1';
vector<string> v;

Ideally I want the strings 'abc' and 'test, 1' to be stored without the single quotes as below, but I can live with storing them with single quotes:

v[0] = "1";
v[1] = "10";
v[2] = "abc";
v[3] = "test, 1";

Aucun commentaire:

Enregistrer un commentaire