编译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
我在Ubuntu 18.04.1上使用g ++ 7.4.0我不想忽略警告,但可以解决它,谢谢
PS:我尝试将-std = c ++ 0x更改为-std = c ++ 11,但它没有做任何更改
-ansi
在您的命令中删除,它等同于-std=c++98
并会覆盖您先前的标志-std=c++11
。根据C-Dialect-Options,
在C模式下,这等效于-std = c90。在C ++模式下,它等效于-std = c ++ 98。
替换-std=c++0x
为-std=c++11
。
请注意,如果您的编译器支持它,则建议使用最新的c ++标准-std=c++17
。使用较新的c ++标准通常会使您的代码更短,更易读且性能更高。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句