C ++有cin读取返回字符 [英] C++ having cin read a return character
本文介绍了C ++有cin读取返回字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用 cin
,如果用户没有输入任何值,只需按 ENTER
cin
会将此视为有效输入。
I was wondering how to use cin
so that if the user does not enter in any value and just pushes ENTER
that cin
will recognize this as valid input.
推荐答案
可能想尝试 std :: getline
:
#include <iostream>
#include <string>
std::string line;
std::getline( std::cin, line );
if( line.empty() ) ...
这篇关于C ++有cin读取返回字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文