我的学校程序中的一个函数抛出此异常:
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));
}
我认为这行:int age = stoi(parsedDataRow.at(4));
导致此问题,因为向量中的元素少于5个。请记住,C ++向量是基于0的。