无法编译C++ file.cpp.C++ 98模式

ka4*_*eli 1 c++ vim ubuntu gcc c++98

我是C++的新手.当我写作

for (char* c : v)
{
    cout << c;
}
Run Code Online (Sandbox Code Playgroud)

我明白了

在C++ 98模式下不允许使用"基于范围的''循环"

据我了解,我必须更改我的GCC版本(或只是模式?).我的g++ -v:

使用内置规格.COLLECT_GCC = g ++ COLLECT_LTO_WRAPPER =/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper目标:i686-linux-gnu配置为:../ src/configure -v --with-pkgversion ='Ubuntu/Linaro 4.7.2-2ubuntu1' - with-bugurl = file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages = c,c ++,go,fortran,objc,obj-c ++ --prefix =/usr --program-suffix = -4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir =/usr/lib --without-included-gettext --enable-threads = posix --with-gxx-include-dir =/usr/include/c ++/4.

无法从vim(使用c.vim插件),sublime text3和终端使用gcc program.cpp和编译gcc -pedantic -std=c99 program.cpp.

我已经下载了gcc 4.8.1但它不是deb包,所以无法正确安装.还听说过C++ 11,C++ 14,C++ 98,C++ 99.我在哪里/如何获得/安装最新版本?

vim插件c.vim的解决方案:

编辑"c.vim/plugin/c.vim".改变这一行

let s:C_CplusCFlags = '-Wall -g -O0 -c -std=c++11' " C++ compiler flags: compile, don't optimize

我添加了"-std = c ++ 11"并且它有效.

use*_*699 5

基于for循环范围是C++ 11的一部分,因此您需要使用-std=c++11G ++来启用C++ 11功能.