我收到了错误
error: 'INT32_MAX' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
但我已经包括在内了
#include <stdint.h>
Run Code Online (Sandbox Code Playgroud)
我正在使用命令编译(g ++(GCC)4.1.2 20080704(Red Hat 4.1.2-44))
g++ -m64 -O3 blah.cpp
Run Code Online (Sandbox Code Playgroud)
我需要做任何其他事情才能编译吗?还是有另一种C++方式来获取常量" INT32_MAX"?
谢谢,如果有什么不清楚,请告诉我!
Bli*_*ndy 47
从手册页引用,"C++实现应该仅在包含__STDC_LIMIT_MACROS之前定义的这些宏时定义<stdint.h>".
所以尝试:
#define __STDC_LIMIT_MACROS
#include <stdint.h>
Run Code Online (Sandbox Code Playgroud)
doc*_*doc 23
#include <cstdint> //or <stdint.h>
#include <limits>
std::numeric_limits<std::int32_t>::max();
Run Code Online (Sandbox Code Playgroud)
请注意,它<cstdint>是一个C++ 11标头,<stdint.h>是一个C标头,包含与C标准库的兼容性.
以下代码工作,自C++ 11以来.
#include <iostream>
#include <limits>
#include <cstdint>
struct X
{
static const std::int32_t i = std::numeric_limits<std::int32_t>::max();
};
int main()
{
switch(std::numeric_limits<std::int32_t>::max()) {
case std::numeric_limits<std::int32_t>::max():
std::cout << "this code works thanks to constexpr\n";
break;
}
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e