我在C ++中遇到“内存位置的out_of_range”问题

时间:2019-09-24 11:46:31

标签: c++ string

BehaviorSubject

// Project1.exe中0x75CCAD12的未处理异常: // Microsoft C ++异常:内存位置0x0073F614的std :: out_of_range。发生

1 个答案:

答案 0 :(得分:0)

for循环的第一次迭代中,您尝试获取indexs[i - 1] == indexs[-1]元素。数组索引从0开始,禁止使用负值。您需要为第一次迭代添加一些特殊处理,例如:

    for (int i = 0; i < 3 ; ++i)
    {   
    if(i == 0)
    {
        // special handling
    }
    else
    {
        pumbaTheString =  pumbaTheString.substr((indexs[i] - indexs[i - 1]), pumbaTheString.length());//here its did the problem
    }
    cout << pumbaTheString << endl;
}
相关问题