gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:43:51 24 4
gpt4 key购买 nike

我试图用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com