Search notes:

C++ preprocessor macro __cplusplus

The __cplusplus preprocessor macro is defined if the compilation unit is compiled with a C++ compiler. Its value corresponds to the C++ standard that the compiler uses to compile a compilation unit.
In PowerShell, its value can quickly be printed like so:
write-output '' | g++ -dM -E -x c++  - | select-string  __cplusplus      # or
ech          '' | g++ -dM -E -x c++  - | findstr        __cplusplus      # or
In other shells with
g++ -dM -E -x c++  /dev/null | grep -F __cplusplus

main.cpp

#include <iostream>
#include <iomanip>

int main(int argc, char* argv[]) {

//  Compile with g++ -std=c++11 or g++ -std=c++14 to
//  have different output.
//  See also https://stackoverflow.com/a/7132549/180275
    std::cout << std::setw(6) << argv[0] << ": " <<  __cplusplus << std::endl;
}
Github repository about-cpp, path: /preprocessor/macros/predefined/__cplusplus/main.cpp

Makefile

all: cpp98 gcc98 cpp1z cpp11 gnu11 cpp14 gnu14 cpp17
	@ ./cpp98
	@ ./gcc98
	@ ./cpp11
	@ ./gnu11
	@ ./cpp14
	@ ./gnu14
	@ ./cpp1z
	@ ./cpp17

cpp98: main.cpp
	@g++ -std=c++98 main.cpp -o cpp98

gcc98: main.cpp
	@g++ -std=gnu++98 main.cpp -o gcc98

cpp11: main.cpp
	@g++ -std=c++11 main.cpp -o cpp11

gnu11: main.cpp
	@g++ -std=gnu++11 main.cpp -o gnu11

cpp14: main.cpp
	@g++ -std=c++14 main.cpp -o cpp14

gnu14: main.cpp
	@g++ -std=gnu++14 main.cpp -o gnu14

cpp1z: main.cpp
	@g++ -std=c++1z main.cpp -o cpp1z

cpp17: main.cpp
	@g++ -std=c++17 main.cpp -o cpp17

clean:
	@rm -f cpp98 gcc98 cpp11 gnu11 cpp14 gnu14 cpp1z cpp17

FORCE: ;
Github repository about-cpp, path: /preprocessor/macros/predefined/__cplusplus/Makefile

Output

./cpp98: 199711
./gcc98: 199711
./cpp11: 201103
./gnu11: 201103
./cpp14: 201402
./gnu14: 201402
./cpp1z: 201500
./cpp17: 201500

See also

Preprocessor: macros
When invoking g++, the standard can be chosen with the compiler option -std.

Index