C++11 中未定义 __STDC_VERSION__?

tow*_*120 5 c++ gcc c++11

我尝试使用__STDC_VERSION__gcc 4.8 和 clang,但它只是没有定义。编译器标志:

g++ -std=c++11 -O0 -Wall -Wextra -pedantic -pthread main.cpp && ./a.out

http://coliru.stacked-crooked.com/a/b650c0f2cb87f26d

#include <iostream>
#include <string>

int main()
{
    std::cout << __STDC_VERSION__  << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

结果:

main.cpp:6:18: error: '__STDC_VERSION__' was not declared in this scope

我必须包含一些标头,或者添加编译器标志?

nma*_*ier 5

官方文档指出:

__STDC_VERSION__

...

如果使用 -traditional-cpp 选项,或者编译 C++ 或 Objective-C 时,则不会定义该宏。

此外,C++ 标准将其留给实现来定义或不定义该宏,而 g++ 选择了后者。

根据您想要执行的操作,__cplusplus宏可能是一种替代方案(它不仅仅是定义的,它也有一个值;)