gpt4 book ai didi

c++ - 跳过 getline

转载 作者:太空宇宙 更新时间:2023-11-04 12:50:22 24 4
gpt4 key购买 nike

<分区>

我试图让这个程序工作,但在它应该读取内容字符串的部分,它只是跳过了。也许是因为缓冲区中已经有一些我不知道的东西。

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;
}

我该怎么办?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com