在编译C++文件时,我收到了以下警告:
variables.cpp:10:8: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
int c{2} ;这是一个文件:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std ;
int main()
{
int a = 0 ;
int b(1) ;
int c{2} ;
string myString = "I am a string !" ;
cout << a+b+c << endl ;
cout << myString << endl ;
return EXIT_SUCCESS ;
}这是命令行:
g++ -std=c++0x -Wall -Wextra -Winit-self -Wold-style-cast -Woverloaded-virtual -Wuninitialized -Wmissing-declarations -Winit-self -ansi -pedantic variables.cpp -o variables我在Ubuntu18.04.1上使用g++ 7.4.0,我不想忽视警告,但是要解决它,谢谢
PS :我试图将-std=c++0x更改为-std=c++11,但它没有改变任何东西。
发布于 2020-01-29 13:18:00
-ansi,这相当于-std=c++98,它将覆盖以前的标志-std=c++11。据C方言-选项称,
在C模式下,这等同于-std=c90。在C++模式下,它与-std=c++98等价。-std=c++0x替换为-std=c++11。注意,如果编译器支持它,建议使用最新的c++标准,即-std=c++17。使用更新的c++标准通常会使您的代码更短、更可读性更强、性能更好。
发布于 2020-01-29 13:43:35
编译命令行有两个问题:
第一个是编译中的-ansi命令,它隐式地将标准设置为c++98。在这种情况下,-ansi选项会生成与-std=c++11的冲突。
第二个是-std=c++0x,您必须用-std=c++11替换它。
https://stackoverflow.com/questions/59967799
复制相似问题