GNU g++4.8.4编译支持c++11标准
2015-12-11 17:24
351 查看
系统:ubuntu14.04
编译器:g++ 4.8.4
问题:在ubuntu14.04下编译如下c++源码出错:
#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
const int i = 42;
auto j = i;
const auto &k = i;
auto *p = &i;
const auto j2 = i, &k2 = i;
cout << typeid(i).name() << endl;
cout << typeid(j).name() << endl;
cout << typeid(k).name() << endl;
cout << typeid(p).name() << endl;
cout << typeid(j2).name() << endl;
cout << typeid(k2).name() << endl;
return 0;
}
这是因为g++ 4.8.4虽然支持c++11,但是编译时不默认使用c++11,需要显示的提醒编译器用c++11,如下是提示编译器
解决办法:在~./bashrc中添加如下两行:
即永久的为g++指定别名‘g++ -std=c++11’
编译器:g++ 4.8.4
问题:在ubuntu14.04下编译如下c++源码出错:
#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
const int i = 42;
auto j = i;
const auto &k = i;
auto *p = &i;
const auto j2 = i, &k2 = i;
cout << typeid(i).name() << endl;
cout << typeid(j).name() << endl;
cout << typeid(k).name() << endl;
cout << typeid(p).name() << endl;
cout << typeid(j2).name() << endl;
cout << typeid(k2).name() << endl;
return 0;
}
这是因为g++ 4.8.4虽然支持c++11,但是编译时不默认使用c++11,需要显示的提醒编译器用c++11,如下是提示编译器
解决办法:在~./bashrc中添加如下两行:
即永久的为g++指定别名‘g++ -std=c++11’
相关文章推荐
- C++输入输出
- C++函数指针
- C语言学习总结(四) 剩余内容
- 第一个c语言程序
- scanf函数详解
- leetcode----Longest Substring Without Repeating Characters
- c++ 植物类 继承多态 菱形继承
- C语言文件操作详解
- C语言中的static 详细分析
- 二叉搜索树(BST) ---- C语言
- [C++]类模板在何时实例化?
- C++第11版本中的一些强大的新特性小结
- C++多态技术的实现和反思
- vs2010 C++静态编译
- C++ Primer Plus第六版 第十六章 编程练习答案
- Loadruuner C语言脚本--如何引用DLL文件
- c++实现hashtable缓存
- 博弈——翻硬币游戏
- C#做界面果然比C++方便
- C++中的临时对象 zz