【发布时间】:2023-03-16 01:58:01
【问题描述】:
我正在尝试读取用户输入,直到按下 ctrl-d。如果我是正确的,ctrl+d 会发出一个 EOF 信号,所以我尝试检查 cin.eof() 是否为真,但没有成功。
这是我的代码:
string input;
cout << "Which word starting which year? ";
while (getline(cin, input) && !cin.eof()) {
cout << endl;
...
cout << "Which word starting which year? ";
}
【问题讨论】: