我遇到错误
error: 'INT32_MAX' was not declared in this scope
但是我已经包含了
#include <stdint.h>
我正在使用命令在(g ++(GCC)4.1.2 20080704(Red Hat 4.1.2-44)上对此进行编译
g++ -m64 -O3 blah.cpp
我需要做其他任何事情来编译它吗?还是有另一种C ++方式来获取常量“ INT32_MAX
”?
谢谢,让我知道是否有任何不清楚的地方!
#include <cstdint> //or <stdint.h>
#include <limits>
std::numeric_limits<std::int32_t>::max();
请注意,<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;
}
从手册页引用,“只有在包含__STDC_LIMIT_MACROS
之前定义<stdint.h>
的情况下,C ++实现才应该定义这些宏”。
所以尝试:
#define __STDC_LIMIT_MACROS
#include <stdint.h>
嗯...我要做的就是#include <climits>
此页面上没有其他对我有用。
授予,我正在尝试使用INT_MIN
。
#include <iostream>
#include <limits.h> or <climits>
为我工作]
[#include <iostream>
为我工作后包括以下代码:
我也面临类似的问题,只需要添加-#include <limits.h>
之后的#include <iostream>
我在使用LLVM 3.7.1 c ++编译器时遇到了类似的问题。在构建某些自定义库的过程中尝试编译gRPC代码时出现以下错误