Reputation: 459
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.
Upvotes: 24
Views: 87147
Reputation: 239443
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
Upvotes: 28
Reputation: 726479
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.
Upvotes: 22