问题描述
我在程序开始时使用了cin.peek()函数,程序问输入peek不只是预览?为什么要求输入?
#include <string>
#include <cctype>
using namespace std;
int main() {
cout << "Please,enter a number or a word: ";
int c = cin.peek();
if (c == EOF) return 1;
if (isdigit(c))
{
int n;
cin >> n;
cout << "You entered the number: " << n << '\n';
}
else
{
string str;
cin >> str;
cout << "You entered the word: " << str << '\n';
}
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)