I have a vector of strings:
vector<string> tokenTotals;
When push_back
is called, a string of length 41 is stored and I must operate on each element of my vector and get two substrings, the first in range 0 to 28 and the second in range 29 to 36:
for(int i = 0; i < tokenTotals.size(); i++)
{
size_t pos = tokenTotals[i].find(": ");
cout << tokenTotals[i] << endl; // Show all strings - OK
cout << tokenTotals[i].length() << endl; // Lenght: 41
string first = tokenTotals[i].substr(0, 28); // OK
string second = tokenTotals[i].substr(29, 36); // ERROR
cout << first << " * " << second << endl;
}
But when I try to get the second substring, I get the following error:
terminate called after throwing an instance of std::out_of_range.
what():: basic_string::substr
Any idea of what could have happened?