我有字符串矢量:的std :: string :: SUBSTR抛出的std :: out_of_range但自变量是在极限
vector<string> tokenTotals;
当push_back
被调用时,长度41的字符串被存储和我必须操作我的向量中的每个元素,并获得两子,先在范围为0〜28,第二次在范围29〜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;
}
但是,当我试图让第二子,我得到以下错误:
terminate called after throwing an instance of std::out_of_range.
what():: basic_string::substr
有什么想法会发生什么?