c++ - 如何让所有输入都在同一行 C++

标签 c++ input cin

我被要求在同一行输入一小时和一分钟。但是当我输入小时时,它会自动换行,我只能在下一行输入分钟。但是,我想在同一行中输入小时和分钟,并在它们之间加一个冒号。它应该是这样的

Time: 4:54 

但是我的代码产生了这个:

Time: 4 

54

cout << "\n\tTime: "; 
cin >> timeHours;
cin.get();
cin >> timeMinutes;

最佳答案

您可以按照以下方式进行操作:

cin >> timeHours >> timeMinutes;

根据documentation :

the user is expected to introduce two values, one for variable a, and another for variable b. Any kind of space is used to separate two consecutive input operations; this may either be a space, a tab, or a new-line character.

关于c++ - 如何让所有输入都在同一行 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647249/

相关文章:

c++ - 寻找 C(++) 中的基本反向 Shell 示例

c++ - 为什么与 Direct X 链接会大大增加我的程序大小?

javascript - INPUT TEXT 删除浏览器默认下拉菜单

c++ - 当 cin 的输入是 'dot' 时 while 循环到无穷大

android - 在 android 上触摸返回按钮时如何移动到 cocos2d-x 中的另一个场景

c++ - boost::filesystem::unicode 文件路径的路径?

java - Java 输入缓冲区中的空字符持久性?

html - 表格内的单选按钮

c++ - 尽管有 cin.ignore(),但 Cin 没有等待输入

c++ - 用户定义类的输入流