How to change gcc compiler to C ++ 11 on ubuntu

I am using ubuntu 12.04 and gcc is 4.6.3 by default. It does not accept C ++ 11 commands and gives me a conclusion saying that the command is not compatible with C ++ 98. I checked online and saw that people advised against changing the default compilers in the operating system, as they become unstable. Can anyone suggest a fix or a safe way to download a gcc compiler compatible with C ++ 11.

+18
c ++ c ++ 11
Jun 29 '13 at 9:57 on
source share
2 answers

gcc 4.6.3 supports many of the features of C ++ 11 . However, they are disabled by default. To enable them, use the following flag:

g++ -std=c++0x ... 

This flag also disables GNU extensions; to enable them, use the -std=gnu++0x flag.

+15
Jun 29 '13 at 10:02
source share

Like others, you need to enter the command line parameter std. Let's simplify for you

  • Open a terminal by pressing Ctrl + Alt + T
  • sudo gedit ~/.bashrc
  • Enter the next line as the last line

     alias g++="g++ --std=c++0x" 
  • Save and close the file and close the terminal.
  • Now open the terminal again and compile your C ++ 11 programs just g++ filename.cpp

Here it is. By default, it will compile for the C ++ 11 standard.

NOTE. . If you follow the option above to compile non-C ++ 11 programs, you should use

 g++ --std=c++98 filename.cpp 
+20
Jun 29 '13 at 10:19
source share



All Articles