How to determine what C++ standard is the default for a C++ compiler?

后端 未结 2 1303
挽巷
挽巷 2020-12-25 12:54

It is frequently mentioned that the -std flag should be used to specify the standard that one wishes to use when compiling a C++ program (e.g., -std=c++11

相关标签:
2条回答
  • 2020-12-25 13:35

    Add to max66's answer. There is no need to compile and execute the program. The same information can be grepped through the preprocessed output using:

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

    The values of the __cplusplus macro gives the value of the standard.

    0 讨论(0)
  • 2020-12-25 13:37

    What about compiling and executing the following trivial program ?

    #include <iostream>
    
    int main()
     { std::cout << __cplusplus << std::endl; }
    

    The value printed should say the version used:

    • 199711 for C++98,
    • 201103 for C++11
    • 201402 for C++14
    • 201703 for C++17

    If you compile omitting the -std=c++xx flag, you should be able to detect the default version of language used.

    0 讨论(0)
提交回复
热议问题