GCC编译器升级到4.8.2,编译C++11的新特性还是不支持?!

Misslio 2014-06-14 12:22:45
最近在学习C++,看的是《C++ Primer》的第五版,在centos6.2上升级了GCC到4.8.2版本后,程序编译显示不过.提示还说是C++98不允许。作为一个初学者,在此求教:

可以看到版本已经是4.8.2了
/************g++ 版本*************/
[root@bogon 11]# g++ --version
g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/************************************/

/*********** *编译提示 ****************/
associate.cc:23:18: error: ISO C++ forbids declaration of ‘w’ with no type [-fpermissive]
for(const auto &w : word_count)
^
associate.cc:23:22: error: range-based ‘for’ loops are not allowed in C++98 mode
for(const auto &w : word_count)
/****************************************/

/**************程序********************/
#include <iostream>
2 #include <map>
3 #include <string>
4 #include <set>
5
6
7 using namespace std;
8
9 int main()
10 {
11 map<string,size_t> word_count;
12 string word;
13 set<string> exclude;
14
15
16 while(cin >> word)
17 {
18 if(word == "quit")
19 break;
20 else if(exclude.find(word) == exclude.end())
21 ++word_count[word];
22 }
23 for(const auto &w : word_count)
29 cout << w.first << ": " << w.second\
30 << ((w.second > 1) ? " times" : " time") << endl;
31 }
/**********************************************************************/
...全文
2788 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Miss_lapland 2016-03-22
  • 打赏
  • 举报
回复
你好,可以发个GCC4.8.2的安装包到邮箱1659888231@qq.com不,谢谢~
tyo23 2015-10-22
  • 打赏
  • 举报
回复
最近也遇见这个在LINUX上,搜了下,答案是: Well, specify that string among other compiler options in the command line, like this: g++ -std=c++11 -o test_executable test_source.cpp 看来格式是这样的啊。
碼上道 2014-06-14
  • 打赏
  • 举报
回复
加一个编译选项 -std=c++11
JPF1024 2014-06-14
  • 打赏
  • 举报
回复
引用 4 楼 u014260236 的回复:
原来是这样,谢谢楼上二位,可以了。
07q.net多交流
Misslio 2014-06-14
  • 打赏
  • 举报
回复
原来是这样,谢谢楼上二位,可以了。
Morrisss_ 2014-06-14
  • 打赏
  • 举报
回复
要强制开启,或者在cmake里设置。
JPF1024 2014-06-14
  • 打赏
  • 举报
回复
g++ test.cpp -o test.out -std=c++0x -Wall 最后那个是编译警告,初学打开比较好 gcc目前需要添加-std=c++0x 才能顺利编译c++11新特性

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧