Skip to content

Instantly share code, notes, and snippets.

@drawcode
Last active April 21, 2025 18:14
Show Gist options
  • Save drawcode/a46d05947a4e5927536bc82077db2a87 to your computer and use it in GitHub Desktop.
Save drawcode/a46d05947a4e5927536bc82077db2a87 to your computer and use it in GitHub Desktop.
C++ version check
// 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