【发布时间】:2018-08-16 00:36:10
【问题描述】:
我有以下代码,我正在尝试创建一个非常简单(不是那么简单)的待办事项列表。期望的结果如下:
1) 醒来 2) 感谢上帝,我还活着。
...C++
#include <iostream>
#include <string>
using namespace std;
int main() {
string list_entry;
cout << "What would you like to add to your to-do list?" << endl;
int count = 1;
while (true) {
getline(cin,list_entry)
cout << count << ")" << list_entry << endl;
count++;
}
return 0;
}
...C++
...输出
我得到以下输出,这不是预期的结果:
What would you like to add to your to-do list?
Wake up
1)Wake up
Thank God I'm alive
2)Thank God I'm alive
Make the bed
3)Make the bed
...输出
期望的结果如下:
您想在待办事项列表中添加什么? 1)醒来 2)感谢上帝我还活着 3) 铺床 等等
【问题讨论】:
-
摆脱
cin.ignore();
标签: c++ string input counter cin