为“find_first_of”引发错误“out_of_range”

时间:2015-01-12 15:56:43

标签: c++ string

我不知道为什么第一个代码块正常工作而第二个代码块不工作: 对于这两个块,有:

struct Object
{
    vector <string> line;
};

Object myObject;
string a = "*Nset, nset=_PickedSet2, internal, generate";
myObject.line.push_back(a);
int iPos = 0; 
int iPos2 = 7;  
string sRefString = ",";     // So I want to find the ",".
iPos = myObject.line.at(0).find_first_of(sRefString, iPos2);    //Here is the issue.

所以这很好用:

cout <<"Output: "<< myObject.line.at(0).find_first_of(sRefString, iPos2);

它给出了:

Output: 23

但这不是:

iPos = myObject.line.at(0).find_first_of(sRefString, iPos2);

我在这里得到一个错误:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
zweiterminate called after throwing an instance of 'std::out_of_range'
what():  basic_string::substr

感谢您的帮助!

0 个答案:

没有答案