跳过获取线
Skiping the getline
本文关键字:获取 更新时间:2023-10-16
我正在尝试使该程序工作,但在它应该读取内容字符串的部分,它只是跳过。也许是因为缓冲区中已经有一些我不知道的东西。
struct Task {
int priority;
string content;
Task * nxtTask;
};
void addTask(Task *, int, string);
Task * newTask(int, string, Task *);
int main() {
Task * t1 = nullptr;
int choice;
do {
string content;
cin >> choice;
switch(choice) {
case 1:
break;
case 2:
cout << "Enter the priority of the task.n>? ";
int priority;
cin >> priority;
cout << "What's the content of the task?n>? ";
getline(cin, content);
addTask(t1, priority, content);
break;
case 3:
break;
};
} while (choice > 0);
return 0;
}
Task * newTask(int priority, string content, Task * nxtTask) {
Task * task = new Task;
task->priority = priority;
task->content = content;
task->nxtTask = nxtTask;
return task;
}
void addTask(Task * t1, int priority, string content) {
t1 = newTask(priority, content, nullptr);
return;
}
我该怎么办?
add cin.clear((在上线之前
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 在c++中获取大文件的大小