check compiler version c++
To check the version of the C++ compiler, you can use the __cplusplus
macro. Here are the steps to do that:
Open a C++ source file in a text editor or an integrated development environment (IDE).
Locate a place in your code where you can add a simple code snippet to check the compiler version.
Add the following code snippet to your C++ source file:
#include <iostream>
int main() {
std::cout << "C++ Version: " << __cplusplus << std::endl;
return 0;
}
Save the file with a
.cpp
extension. For example, you can save it asversion.cpp
.Open a terminal or command prompt and navigate to the directory where you saved the
version.cpp
file.Compile the C++ source file using a C++ compiler. The exact command may vary depending on the compiler you are using. Here are some common commands for popular compilers:
GCC/G++:
g++ version.cpp -o version
- Clang:
clang++ version.cpp -o version
Microsoft Visual C++ (MSVC):
cl version.cpp
Run the compiled executable. The exact command may vary depending on your operating system. Here are some common commands for different systems:
Linux/macOS:
./version
Windows:
version.exe
The output of the program will display the version of the C++ compiler being used.
For example, if you are using GCC/G++, the output might look like:
C++ Version: 201703
In this case, the 201703
indicates that you are using the C++17 standard.
Please note that the __cplusplus
macro provides a value that corresponds to the version of the C++ standard being implemented by the compiler. The values for different C++ standards are:
- C++98: 199711L
- C++03: 199711L
- C++11: 201103L
- C++14: 201402L
- C++17: 201703L
- C++20: 202002L
It's important to note that the values for C++ standards may vary depending on the compiler and its version.