0

Here's my Code. I even added but for some reasons it still gives me Errors and i typed it exactly like in the tutorial i'm watching. I dont know what to do (ignore that text i just need some words, so that i can send this question out) :

#include <iostream>
#include <list> 
#include <limits>

class ToDoList{
private:
    std::string name; 
    std::list<std::string> myList;
public:
    ToDoList(){ // Konstruktor 1
        this->name = "TODO LIST";
    }
    ToDoList(std::string name){
        this->name = name;
    }
    void insertTask(); 
    void removeTask(); 
    void showList(); 
    void showMenu(); 
};

void ToDoList::showMenu(){
int choice = -1;  
bool fail; // Diese Variable hält fest, ob der User-Input korrekt war
do {
    std::cout << this->name << std::endl;
    std::cout << "-------------------" << std::endl;
    std::cout << "(1) Aufgabe eingeben" << std::endl;
    std::cout << "(2) Aufgabe aus der Liste hinzufügen" << std::endl;
    std::cout << "(3) ToDo-Liste anzeigen" << std::endl;
    std::cout << "(0) Abbrechen" << std::endl;
    std::cout << "-------------------" << std::endl;
    std::cout << "Deine Auswahl: ";
    std::cin >> choice;
    fail = std::cin.fail();
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), "\n");
} while (fail || choice < 0 || choice > 3);

sdt::cout << "Deine Auswahl war: " << choice << std::endl;
}

int main(int argc, const char * argv[]) {
ToDoList myList;
myList.showMenu
std::cout << "\n";
return 0;
}
  • 1
    `std::cin.ignore(std::numeric_limits::max(), "\n");` ==> `std::cin.ignore(std::numeric_limits::max(), '\n');` – n. m. could be an AI Aug 07 '22 at 10:20
  • Exact dupe: [How to properly use cin.clear an cin.ignore](https://stackoverflow.com/questions/52305917/how-to-properly-use-cin-clear-an-cin-ignore) – Jason Aug 07 '22 at 10:25

0 Answers0