Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to determine the version of the C++ standard used by the compiler?
Sometimes we need to know that, what is the current C++ standard. To get this kind of information, we can use the macro called __cplusplus. For different standards, the value of this will be like below.
| Standard | __cplusplus output |
|---|---|
|
C++ pre C++98 |
1 |
|
C++98 |
199711L |
|
C++98 + TR1 |
This cannot be checked, this will be marked as C++98 |
|
C++11 |
201103L |
|
C++14 |
201402L |
|
C++17 |
201703L |
Example
#include<iostream>
int main() {
if (__cplusplus == 201703L)
std::cout << "C++17" << endl;
else if (__cplusplus == 201402L)
std::cout << "C++14" << endl;
else if (__cplusplus == 201103L)
std::cout << "C++11" << endl;
else if (__cplusplus == 199711L)
std::cout << "C++98" << endl;
else
std::cout << "pre-standard C++" << endl;
}
Output
C++98
Advertisements