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

最近常用到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!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值