Linux下无法编译含C++11新特性的程序
来源:互联网 发布:java数据库课程设计 编辑:程序博客网 时间:2024/06/01 10:05
今天在学C++中的auto关键字时,在
Linux version 4.10.0-28-generic
Ubuntu 16.04.3
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
环境下编译以下测试程序时会报错
#include<iostream>#include<vector>using namespace std;int main(void){ vector<int> v{1,2,3,4,5}; for(auto &i : v) i *= i; for(auto i : v) cout << i << " "; cout<<endl; return 0;}~
这是个非常简单的程序,肯定不会有什么大问题,但是系统报错了一大堆
/usr/include/c++/5/bits/stl_vector.h:253:7: note: candidate expects 0 arguments, 5 providedtest.cpp:8:14: error: ISO C++ forbids declaration of ‘i’ with no type [-fpermissive] for(auto &i : v) ^test.cpp:8:18: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11 for(auto &i : v) ^test.cpp:10:13: error: ‘i’ does not name a type for(auto i : v) ^test.cpp:12:4: error: expected ‘;’ before ‘cout’ cout<<endl; ^test.cpp:13:4: error: expected primary-expression before ‘return’ return 0; ^test.cpp:13:4: error: expected ‘)’ before ‘return’
由于我是刚开始接触C++11的相关知识,所以我刚开始以为是我的g++版本太低(上面是已经升级的版本),所以升级了版本,但是还是一样的,后来经过上网查询来找到我犯的错误是什么,原来如果程序中包含C++11的相关新特性要在编译时加后缀-std=c++11
所以我g++ test.cpp -std=c++11就编译成功了
阅读全文
0 0
- Linux下无法编译含C++11新特性的程序
- C++11的新特性在linux下终端中的编译运行
- Linux下c程序的编译方法:
- linux下c程序的编译过程
- linux下C程序的编译链接
- LINUX下编译c程序
- Linux 下编译C程序
- Linux下编译C程序
- Linux下编译C程序
- Linux下编译C程序
- linux下编译C程序
- linux 下,编译c程序
- linux下命令行下编译c程序
- linux下命令行下编译c程序
- linux下命令行下编译c程序
- Linux 下编译hello world 的C 语言程序
- Linux 下编译hello world 的C 语言程序
- linux下c程序的编辑编译运行调试
- host端口转发
- Python类的一些概念
- css3动画效果和响应式
- 多个数据库查询方案
- 两个fragment之间传参数方法
- Linux下无法编译含C++11新特性的程序
- mysql驱动包的版本问题
- git错误Repository not found
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 文本相似度simhash算法-简单说
- 用于理解Java的前8个图表
- sharepoint2016条纹码
- 第一章:why AI
- JNDI