我想这段代码unordered_map判断钥匙是否在地图
#include <iostream>
#include <utility>
#include <vector>
#include <unordered_map>
#include <stdexcept>
using namespace std;
int main() {
unordered_map<int,int> parent_map;
try {
int a = parent_map[0];
cout<<a<<endl;
} catch (out_of_range oe) {
cout<<"out of range"<<endl;
}
return 0;
}
我觉得超出范围的异常应该被捕获。然而,输出是
0
我很困惑。我记得之前我有这个工作。
你想用'at'捕捉到异常。 – Pubby 2013-02-13 06:50:26