【发布时间】:2015-10-09 22:07:03
【问题描述】:
我试图理解字符串中的out_of_range 异常
#include<iostream>
#include<exception>
using namespace std;
int main()
{
try{
string str = "Hello";
str.at(100);//throws exception and get caught
//str[100]; //this is a run time error, program crashes
}
catch (out_of_range &e)
{
cout << e.what() << endl;
}
}
为什么对字符串的数组访问不抛出任何异常和崩溃,而.at 工作正常?
IDE:VS2013
【问题讨论】:
标签: c++ exception indexoutofboundsexception