I use ubuntu 12.04 and the default gcc is 4.6.3. It is not accepting c++11 commands and is giving me output saying the command is not c++98 compatible. I checked online and have seen people advising to not change default compilers on operating system as it becomes unstable. Can anybody suggest a fix or a safe way of downloading a gcc compiler that is c++11 compliant.
According to cppreference, full support of c++11 came with gcc 4.8. 1; To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.
You need to add the option --std=c++11 (not c+11) to the compiler's command line, which tells the compiler to use the STanDard language version called C++11.
You can use command-line flag -std to explicitly specify the C++ standard. For example, -std=c++98 , or -std=gnu++98 (C++98 with GNU extensions) -std=c++11 , or -std=gnu++11 (C++11 with GNU extensions)
As others have suggested, you need to enter the std commandline option. Let us make it easy for you
sudo gedit ~/.bashrc
Enter the following line as the last line
alias g++="g++ --std=c++0x"
g++ filename.cpp
Thats it. By default it will compile for c++11 standard.
NOTE: If you follow the above mentioned option, to compile non-c++ 11 programs, you have to use
g++ --std=c++98 filename.cpp
gcc 4.6.3 supports many c++11 features. However, they are disabled by default. To enable them, use the following flag:
g++ -std=c++0x ...
This flag also disables GNU extensions; to keep them enabled, use -std=gnu++0x
flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With