本文共 731 字,大约阅读时间需要 2 分钟。
我的理解是客观的:
我想要显示的结果后
方案保持开放何乐而不为呢典型的c++方式?
#include
int main(void)
{
int i;
char ch;
std::cout<
std::cin.get(ch); // For testing enter a string at this step say "String"
/* The input to cin is line-buffered, so after reading 'S' to ch,
* the remaining "tring" is still in the buffer.
*/
std::cout<
while(std::cin.get()!='\n')
;;
/* cin.get() is an overloaded function in the istream class.
* If no arguments are passed to 'get()' this function reads single next character
* In essence, we wait for the cin.get() to clear the buffer that is
* read all characters including '\n'
*/
std::cout<
std::cin.get();
/* Since we have already cleared the buffer using the loop
* 'get()' expects us to enter a character this time
*/
return 0;
}
转载地址:https://blog.csdn.net/weixin_30596151/article/details/119161107 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!