您的位置:首页 > 产品设计 > UI/UE

使用unordered_map编译报#error This file requires compiler and library support

2015-07-24 13:22 11017 查看
最近常用到unordered_map,但是我发现这个库在vc6中不能用,无赖只好换成vs2012,测试可以用。然而,我在linux下用g++编译时,出现了以下错误:

In file included from /usr/include/c++/4.8/unordered_map:35:0,

from cul.cc:3:

/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

#error This file requires compiler and library support for the \

^

cul.cc: In member function ‘int Solution::lengthOfLongestSubstring(std::string)’:

cul.cc:15:4: error: ‘unordered_map’ was not declared in this scope

unordered_map<char,int> hash;

....

后面的信息可以看出,是说unordered_map没有定义,我在网上查找了下发现g++4.4之后都支持,我用的是4.8,应该可以正常使用的。最后看到这句:This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11
compiler options.发现时需要编译时加上-std=c++11这个参数,才可以使用,如下:

g++ -std=c++11 -g -o cu cul.cc

发现编译OK!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: