如何忽略标准输入的下一个整数
How to ignore the next int from standard input
假设我想忽略来自标准输入的下一个 int
。我显然可以做到这一点
int a;
std::cin >> a;
// do nothing with a
但是有没有可能不创建一个无用的变量呢?
你可以做到
std::cin.ignore(INT_MAX, ' '); // if ' ' is after the integer
假设我想忽略来自标准输入的下一个 int
。我显然可以做到这一点
int a;
std::cin >> a;
// do nothing with a
但是有没有可能不创建一个无用的变量呢?
你可以做到
std::cin.ignore(INT_MAX, ' '); // if ' ' is after the integer