c++ - Attempting to use std::getline() results in an error? - Stack Overflow

I am trying to build a simple console to-do list. I built a struct with its various properties. Now, I

I am trying to build a simple console to-do list. I built a struct with its various properties. Now, I am trying to build a function that will allow users to input their own data:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct task {
     string Name;
     string Description;
     string DueDate;
     bool isCompleted = false; 
};

task createTaskFromUser() {
     task Task;
     cout << "Enter Task Title";
     getline(cin, task.name);
}

int main() {
    vector<task> taskList;
    int choice;

    cout << "Choose from following:\n1: Add Task\n2: Delete Task\n3: Show All Tasks\n";
    cin >> choice;
    if (choice == 1) {
        cout << "Create New Task:\n"; cout << task; 
    }

    return 0;
}

...however, when I use getline() it comes up with an error.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744170591a4561516.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信