error: 'INT32_MAX' was not declared in this scope

后端 未结 7 1311
谎友^
谎友^ 2020-12-03 06:56

I\'m getting the error

error: \'INT32_MAX\' was not declared in this scope

But I have already included

#include 

        
7条回答
  •  死守一世寂寞
    2020-12-03 07:20

     #include  //or 
     #include 
    
     std::numeric_limits::max();
    

    Note that is a C++11 header and is a C header, included for compatibility with C standard library.

    Following code works, since C++11.

    #include 
    #include 
    #include 
    
    struct X 
    { 
        static const std::int32_t i = std::numeric_limits::max(); 
    };
    
    int main()
    {
        switch(std::numeric_limits::max()) { 
           case std::numeric_limits::max():
               std::cout << "this code works thanks to constexpr\n";
               break;
        }
        return EXIT_SUCCESS;
    }
    

    http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e

提交回复
热议问题