'numeric_limits'未在此作用域中声明,没有匹配的函数调用'max()' [英] ‘numeric_limits’ was not declared in this scope, no matching function for call to ‘max()’

查看:1982
本文介绍了'numeric_limits'未在此作用域中声明,没有匹配的函数调用'max()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译这段代码在家里我的mac w / xcode和没有任何问号。我在linux上用g ++编译它,我得到这些错误:

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'不是std的成员

:expected primary -expression before'>'token

:没有匹配的函数调用'max()'

:‘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;    
} 



我会geussing也许我必须包括一个额外的标题。如果我拿走std ::它只是给我一个类似的错误

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'没有在这个范围内声明

‘numeric_limits’ was not declared in this scope

推荐答案

您需要包含头文件< limits> ,其中 std: :numeric_limits 。您的Mac编译器通过自动包括该头文件帮助你;但是,您不应该依赖该行为,并明确包括您需要的任何头文件。

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.

这篇关于'numeric_limits'未在此作用域中声明,没有匹配的函数调用'max()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆