‘numeric_limits’ was not declared in this scope, no matching function for call to ‘max()’

蹲街弑〆低调 提交于 2019-12-22 01:26:29

问题


I compiled this code at home on my mac w/ xcode and there was no provblem. I compile it at school with g++ on linux and I get these errors:

:‘numeric_limits’ is not a member of std
:expected primary-expression before ‘>’ token
:no matching function for call to ‘max()’

#include <iostream>
#include <cstdlib>

using namespace std;

int GetIntegerInput(int lower, int upper)
{
    int integer = -1;
    do
    {    
        cin >> integer;
        cin.clear();
        cin.ignore(std::numeric_limits<streamsize>::max(), '\n');  //errors here
    }while (integer < lower || integer > upper);

    return integer;    
} 

I'm geussing maybe I have to include an extra header. If I take away the std:: it just gives me a similar error

‘numeric_limits’ was not declared in this scope


回答1:


You need to include the header file <limits>, which is where std::numeric_limits is defined. Your Mac compiler was helping you out by automatically including that header file; however, you should not rely on that behavior and explicitly include any header files you need.



来源:https://stackoverflow.com/questions/4798936/numeric-limits-was-not-declared-in-this-scope-no-matching-function-for-call-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!