C++ problem extracting a substring - extra character
This is really simple and I don't understand why my code doesn't work properly. I have strings in the form "(a,b)", where a and b are numbers and I just want to store those strings in variables (so a in one variable, b in another and not keeping the brackets or the comma). My code looks like this (irrelevant bits omitted):
string a = second.substr(1, str.find(',', 1) - 1);
string b = second.substr(str.find(',', 1) + 1, second.length() - 2);
cout << str[str.length() - 2] << endl;
Here's an example string: (2108974854,0). Printing out the variable a is OK and I get "2108974854", but printing out b, I get "0)". What I find strange is that if I print out str[str.length() - 2] as I have done above, I get "0" as I should.