Last active
April 21, 2025 18:14
-
-
Save drawcode/a46d05947a4e5927536bc82077db2a87 to your computer and use it in GitHub Desktop.
C++ version check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create basic cplusplus main | |
#include <iostream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
std::cout << std::endl; | |
std::cout << "C++ Version: " << std::endl; | |
/* | |
see this on SO <https://stackoverflow.com/questions/2324658/how-to-determine-the-version-of-the-c-standard-used-by-the-compiler> | |
C++ pre-C++98: __cplusplus is 1. | |
C++98: __cplusplus is 199711L. | |
C++98 + TR1: This reads as C++98 and there is no way to check that I know of. | |
C++11: __cplusplus is 201103L. | |
C++14: __cplusplus is 201402L. | |
C++17: __cplusplus is 201703L. | |
C++20: __cplusplus is 202002L. | |
C++23: __cplusplus is 202302L. | |
*/ | |
std::cout << __cplusplus << std::endl; | |
cout << endl; | |
// To limit by version | |
#if __cplusplus >= 202302L | |
// C++23 or later | |
#else | |
// Earlier C++ standard | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment