简体   繁体   English

C ++仅接受第一个cin输入

[英]C++ only accept first cin input

When the program asks the user for an integer input, the user has the ability to input "4 9" and the program uses both.当程序要求用户输入整数时,用户可以输入“ 4 9”,并且程序会同时使用两者。 But what I need is for the program to only accept the first input, in this example "4".但是我需要的是程序仅接受第一个输入,在此示例中为“ 4”。

int input;

cout << "Enter a number" << endl;
cin >> input;

Basically, the question is, how do I make sure the input does NOT have any white spaces in between integers基本上,问题是,如何确保输入在整数之间没有任何空格

When the program asks the user for an integer input, the user has the ability to input "4 9" and the program uses both.当程序要求用户输入整数时,用户可以输入“ 4 9”,并且程序会同时使用两者。 But what I need is for the program to only accept the first input, in this example "4".但是我需要的是程序仅接受第一个输入,在此示例中为“ 4”。

int input;

cout << "Enter a number" << endl;
cin >> input;

Basically, the question is, how do I make sure the input does NOT have any white spaces in between integers基本上,问题是,如何确保输入在整数之间没有任何空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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