0

I've been trying to break up a string that has a delimiter, in this case it is a comma.

int main()
{
string test = "12345,768,11,987,567812";
int temp = 0;
for (int i = 0; i < test.size(); i++) {
    if (test[i] == ',') {
        cout << test.substr(temp, i) << endl;
        temp = i+1;
    }
}

return 0;
}

This is the code I have so far. The first string gets broken up correctly but after that it doesn't work and I'm not sure why.

  • [Parameter 2 of `substr` is length, not position.](https://en.cppreference.com/w/cpp/string/basic_string/substr) – user4581301 Oct 13 '21 at 18:55

0 Answers0