C++ 用户输入关闭程序调试

标签 c++ debugging loops while-loop switch-statement

我有一个 C++ 程序,它等待用户输入,只有在用户输入“q”时才会关闭,如果输入任何其他内容,则会循环返回菜单。

至少这是它应该做的。程序不会返回,而是会关闭。

int main()
{   
    Hierarchy roster;
    char input=' ';
    bool done = false;
    string first, last, full, boss, title;
    while (done != true){
    cout << "Organizational Chart builder, version 0.1" << endl;
    cout << "Please choose your next command: /n";
    cout << "    q   to quit the program " << endl;
    cout << "    a   to add a person " << endl;
    cout << "    c   to count the number of people under someone" << endl;
    cout << "    p   to print the hierarchy " << endl;
    cout << "    r   to remove someone from the hierarchy " << endl;

    cin >> input;

    switch(input)
    {
    case 'q':
        done = true;
        break;
    case 'a':

        cout << "Please enter the person't first name:  ";
        cin >> first;
        cout << "Please enter the person's last name:  ";
        cin >> last;
        cout << "Please enter the person's title";
        cin >> title;
        cout << "Please enter " + first + last +"'s boss. Please enter the full name and title.  If there is none, type none:";
        cin >> boss;
        if (boss == "none")
        roster.insert(full);
        else 
        roster.contains(boss);
        roster.insert(full);
        break;

    case'c':

        cout << "Enter the first name of the person you are searching for:   ";
        cin >> first;
        cout << "Enter the last name:  ";
        cin >> last;
        cout << "What is the person's title:";
        cin >> title;
        full = first + " " + last + " " + title;
        roster.contains(full);
        roster.countb(full);
        break;

    case 'p':
        roster.print();
        break;

    case 'r':

        cout << "Please enter the first, last, and title of the person you want removed:  ";
        cin >> full;
        roster.removeNode(full);
        break;

    }
  }
cout << "Program closed.  " << endl;
return 0;
    }

编辑:现在可以使用了。谢谢

最佳答案

您的返回语句在您的 while 循环中。把它拿出来,你应该没问题。

即。 返回 0;}} -> } return 0;}

关于C++ 用户输入关闭程序调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23670093/

相关文章:

c++ - std::array: `at(-2)`为什么没有警告或错误?

javascript - chrome - 在调试脚本中相当于 Visual Studio 的 F5

C::how:运行错误检查循环中的字符串是否太长

c - 为什么 while 循环不能正常工作?

javascript - for 循环不迭代所有数组

c++ - 包含动态分配数组的结构中的复制构造函数是否总是必要的?

c++ - 使用数组时的抽象与性能

debugging - PyCharm调试器在 “Waiting for connection”结束后停止容器

c++ - 模板函数重载的实例化

c++ - GDB加载so文件失败并报错No such file or directory