简体   繁体   中英

Why does cin.ignore() request input?

I discovered some very peculiar behaviour. I'm new to C++ so I found this odd and was unable to explain it after reading the docs on cin.ignore.

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    cin.ignore(10000, '\n');
    return 0;
}

The code above accepts input. If you add int test; cin>>test; right above cin.ignore, it will not accept input.

当您添加整数的输入时,在输入缓冲区中保留换行符(至少),然后由ignore读取。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM