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

后端 未结 9 567
故里飘歌
故里飘歌 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:15

    Your question is specific to gnu compilers, so probably better to tag it appropriately, rather than just C++ and C++11.

    Your code will compile with any compilers (and associated libraries) compliant with C++11 and later.

    The reason is that C++11 introduced a std::ifstream constructor that accepts a const std::string &. Before C++11, a std::string could not be passed, and it would be necessary in your code to pass filename.c_str() rather than filename.

    According to information from gnu, https://gcc.gnu.org/projects/cxx-status.html#cxx11, gcc.4.8.1 was the first version to fully support C++11. At the command line g++ -v will prod g++ to telling you its version number.

    If you dig into documentation, you might be able to find the version/subversion that first supported enough features so your code - as given - would compile. But such a version would support some C++11 features and not others.

    Since windows isn't distributed with g++, you will have whatever version someone (you?) has chosen to install. There will be no default version of g++ associated with your version of windows.

提交回复
热议问题