Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:';INT32_MAX';未在此范围中声明_C++ - Fatal编程技术网

C++ 错误:';INT32_MAX';未在此范围中声明

C++ 错误:';INT32_MAX';未在此范围中声明,c++,C++,我发现了错误 error: 'INT32_MAX' was not declared in this scope 但我已经包括在内了 #include <stdint.h> 我还需要做些什么来编译它吗?还是有另一种C++方法得到常数“ 谢谢,如果有什么不清楚的地方请告诉我 引自手册页,“C++实现应仅在包含之前定义\u STDC\u LIMIT\u宏时定义这些宏” 因此,请尝试: #define __STDC_LIMIT_MACROS #include <stdint.h&

我发现了错误

error: 'INT32_MAX' was not declared in this scope
但我已经包括在内了

#include <stdint.h>
我还需要做些什么来编译它吗?还是有另一种C++方法得到常数“<代码> 谢谢,如果有什么不清楚的地方请告诉我

引自手册页,“C++实现应仅在包含
之前定义
\u STDC\u LIMIT\u宏时定义这些宏”

因此,请尝试:

#define __STDC_LIMIT_MACROS
#include <stdint.h>
\define\u STDC\u LIMIT\u宏
#包括
#包括//或
#包括
标准::数值限制::最大值();
请注意,
是一个C++11头文件,
是一个C头文件,包括它是为了与C标准库兼容

从C++11开始,下面的代码就可以工作

#include <iostream>
#include <limits>
#include <cstdint>

struct X 
{ 
    static constexpr 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;
}
#包括
#包括
#包括
结构X
{ 
静态constexpr std::int32_t i=std::numeric_limits::max();
};
int main()
{
开关(std::numeric_limits::max()){
case std::numeric_limits::max():

std::cout在
之后包含以下代码#include
对我有效:

#include <limits.h>
#包括
我正在使用以下编译器:


g++5.4.0-6

Hm…我所需要做的就是
#包括
本页面上的其他内容对我来说都不管用


诚然,我试图使用
INT\u MIN
我也面临着类似的问题,只需添加-
\include
\include
之后 #包括或

在使用LLVM 3.7.1C++编译器的情况下,我遇到了类似的问题。 尝试编译gRPC代码作为构建某些自定义库的一部分时出现以下错误

src/core/lib/iomgr/exec_ctx.h:178:12: error: use of undeclared identifier 'INT64_MAX'
< >编译后添加了代码> -dyasdsdcLimithMaung作为C++编译器的选项之一。
.../bin/c++ -D__STDC_LIMIT_MACROS -I{LIBRARY_PATHS} testlib.cc -o testlib

谢谢!我在阅读手册页时错过了这一点--,但我需要等待7分钟才能接受你的答案…这应该是被接受的答案。还要确保你把它放在任何其他可能包含stdint.h的include文件之前,而不先设置定义。5年后…仍然不是被接受的答案:p谢谢,Blindy。这是一个大问题公平地说,公认的答案是一样好的,可以说是一种更为C++的做事方式。但是这也是一个很好的了解。这是一个GCC错误:注意这不是等价的,因为它不能被用作编译时常量(即前C++0X)。是的!这就是我所要寻找的,一个C++的方法。感谢你使用<代码> <代码>,编译<代码> -STD= C++ +0x,<代码> iT3xMax < /C> >被定义为常量(至少在这里是[GCC 4.4.4])。Doc,它不是编译时常数。你不能使用语言需要积分常数的那个地方。试试<代码>开关。(1) {case std::numeric_limits::max():}
struct X{static const int i=std::numeric_limits::max();}
。顺便说一句,我并不是说
不好,只是指出了一个区别。学究:需要限定
std::int32_t
,因为
.h
不包括在内,而且是为了一般的良好实践。@WalterTross Baaad baad的想法,@IanNorton,也许你是对的,但我还是要看看int32_MAX是一个不同的地方我的Eclipse(Helios)/MinGW安装程序没有突出显示为错误,我可以右键单击并打开声明,但我必须将“include”更改为“include”,以停止INT_MAX报告“未在此范围内声明”错误。
#include <iostream>
#include <limits.h> or <climits>
src/core/lib/iomgr/exec_ctx.h:178:12: error: use of undeclared identifier 'INT64_MAX'
.../bin/c++ -D__STDC_LIMIT_MACROS -I{LIBRARY_PATHS} testlib.cc -o testlib