c++ - __STDC_VERSION__ 未在 C++11 中定义?

标签 c++ gcc c++11

我试图用 gcc 4.8 和 clang 获取 __STDC_VERSION__,但它只是没有定义。 编译器标志:

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;
}

结果:

main.cpp:6:18: 错误:“__STDC_VERSION__”未在此范围内声明

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

最佳答案

official documentation状态:

__STDC_VERSION__

...

This macro is not defined if the -traditional-cpp option is used, nor when compiling C++ or Objective-C.

此外,C++ 标准将定义这个宏与否的实现留给了实现,而 g++ 选择了后者。

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

关于c++ - __STDC_VERSION__ 未在 C++11 中定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24477228/

相关文章:

c++ - 编译器是否避免中间整数提升或转换?

c++ - "usr/include/dbus-1.0"在 Maliit 框架中交叉编译不安全

C getline 在换行后继续接受输入

C 编程,将结构体中的 int 成员分配给整数时出现段错误

c++ - C++1y 中是否需要公共(public)类内类型定义?

c++ - 返回数组但也接受函数作为参数的函数

c++ - const int& 性能问题

c++ - Raspberry Pi 3,fann_create_standard 未定义

c++ - 如何使这些 std::function 参数明确?

c++ - 当 || 时如何引起竞争条件在 std::atomic? 中使用运算符而不是 && ?