为什么stoi在此处的内存位置异常处抛出std :: out_of_range?

问题描述 投票:0回答:1

我的学校程序中的一个函数抛出此异常:

    Unhandled exception at 0x757235D2 in C867 - Task 1.exe: 
    Microsoft C++ exception: std::out_of_range at memory 
    location 0x00F5F598.

我不知道如何解决它。我正在尝试从向量中获取某个元素并将其转换为int。

void dg::Roster::parseStudentData(std::string t_dataRow)
{
    std::vector<std::string> parsedDataRow;
    std::stringstream ss(t_dataRow);

    while (ss.good()) {
        std::string subString;
        getline(ss, subString, ';');
        parsedDataRow.push_back(subString);
    }

    int age = stoi(parsedDataRow.at(4));
}


c++ exception visual-c++ stream buffer
1个回答
0
投票

我认为这行:int age = stoi(parsedDataRow.at(4));导致此问题,因为向量中的元素少于5个。请记住,C ++向量是基于0的。

© www.soinside.com 2019 - 2024. All rights reserved.