Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
342 views
Welcome To Ask or Share your Answers For Others

1 Answer

As others have suggested, you need to enter the std commandline option. Let us make it easy for you

  1. Open terminal by pressing Ctrl+Alt+T
  2. sudo gedit ~/.bashrc
  3. Enter the following line as the last line

    alias g++="g++ --std=c++0x"
    
  4. Save and close the file and close the terminal.
  5. Now open terminal again and compile your c++ 11 programs simply by 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...