cin.ignore(numeric_limits::max(), '\n'); max() not recognize it

前端 未结 5 1951
北恋
北恋 2020-12-13 20:44

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.

<
5条回答
  •  误落风尘
    2020-12-13 21:12

    If cin has an error the following will clear the error state and then read in the rest of the line.

    if(!cin)
    {
       cin.clear();
       string junk;
       getline(cin, junk);
    }
    

提交回复
热议问题