首页  

预定义宏 __cplusplus     所属分类 c 浏览量 570
predefined_macro  
___cplusplus


值表示C++的版本
类型是 long int


如果一段代码需要针对C++编写, 可以使用该宏进行条件编译
It is intended that future versions of this standard will replace the value of this macro with a greater value.


C++98
C++03是C++98的修订, 改动很小
ISO C++03 规定该宏的值是 199711L

#include "iostream"
int main(){
  std::cout << __cplusplus << std::endl;
  return 0;
}

用不同的参数编译执行 输出该值

g++ info.cpp
./a.out
199711

g++ -std=c++14 info.cpp
./a.out
201402

g++  -std=c++11 info.cpp
./a.out
201103

g++  -std=c++03 info.cpp
./a.out
199711

g++  -std=c++98 info.cpp
./a.out
199711

上一篇     下一篇
Linux echo输出彩色字符串

C/C++预编译指令

C C++ 宏定义 # 与 ##

c/c++标准预定义宏

c++ 结构体例子

c++ 面向对象 例子