Which C++ standard is the default when compiling with g++?

后端 未结 9 586
故里飘歌
故里飘歌 2020-11-29 23:59

I have a piece of code that looks like the following. Let\'s say it\'s in a file named example.cpp

#include 
#include 

        
9条回答
  •  一向
    一向 (楼主)
    2020-11-30 00:23

    If your version of g++ is later than 4.7 I think you can find the default version of C++ standard supported like so:

    g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
    

    An example from my machine:

    mburr@mint17 ~ $ g++ --version | head -1
    g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
    mburr@mint17 ~ $ g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
    #define __cplusplus 199711L
    

    Some references:

    • Details on the g++ options used
    • Why this only works for g++ 4.7 or later

提交回复
热议问题