unordered_map was not declared in this scope
今天学习STL中的unordered_map()时发现直接使用时会报错:unordered_map was not declared in this scope, 这是由于版本太老,在c++11以前使用都需要加上一些头文件。
搜集资料得出的解决方法为:
直接使用
#include<bits/stdc++.h>时不行的
在cpp中加上如下语句
#include<tr1/unordered_map>//在unordered_map之前加上tr1库名,
using namespace std::tr1;//与此同时需要加上命名空间``
ps:如果你还是使用
using namespace std;
则你需要在每一个unordered_map<string,string> mp;前加上一个str::.
例如tr1::unordered_map<int,int> loc;
参考链接:https://blog.csdn.net/u012530451/article/details/53228098
感谢大佬,我写此博客是为了加深自己的印象,相当于学习笔记了。
版权声明:本文为qq_39072627原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。