cin.ignore(numeric_limits&lt; streamsize&gt; :: max(),'\\\<br/>'); max()不能识别它 [英] cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#39;\n&#39;); max() not recognize it

查看:376
本文介绍了cin.ignore(numeric_limits&lt; streamsize&gt; :: max(),'\\\<br/>'); max()不能识别它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要介绍C ++,我在Win7上使用VStudio 2013。我尝试避免从我的菜单输入错误的数据,它在除了这一个之外的所有人都工作。

I'm taking an intro to C++, and I'm using VStudio 2013 on Win7. I try to avoid the wrong data input from my menus, and it's working in all of them except this one.

    cout << "Please choose your second number" << endl;
    cin >> move2;

    if (move2 < 1 || move2 > size)
    {
        cout << "That's not a valid move" << endl;
        Sleep(2000);
        cin.sync();
        cin.clear();
    }

唯一的区别是在move>不是数字。当我输入一个字符,它回到问题要求另一个输入,但如果我输入一个单词,它打破!

the only difference is that in the condition for move > a variable (size) not a number. When I enter a char it goes back to the question asking for another input, but if I enter a word, it breaks!

我尝试使用 cin.ignore(numeric_limits< streamsize> :: max(),'\\\
');
但是编译器突出显示 max()它说期望的标识符。

I try to use cin.ignore(numeric_limits<streamsize>::max(), '\n'); but the compiler highlights max() and it says "expecting identifier".

这可能很容易为你所有的好程序员,但我不知道如何解决它。

It maybe easy for all of you good programmers, but I don't know how to fix it. Can anybody help me?

推荐答案

这是因为在Visual Studio中使用窗口包括它将定义一个宏max 。如果您将鼠标悬停在示例中的max()上,您应该会收到一个intellisense警告。

This is because in Visual Studio when you use the windows includes it will define a macro max(). If you hover over the max() in your example you should receive an intellisense warning. You can solve this problem by undefining max after all your includes and before any code.

#undef max

这篇关于cin.ignore(numeric_limits&lt; streamsize&gt; :: max(),'\\\<br/>'); max()不能识别它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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