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