Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 程序忽略cin.get()之后的所有内容并跳回菜单_C++ - Fatal编程技术网

C++ 程序忽略cin.get()之后的所有内容并跳回菜单

C++ 程序忽略cin.get()之后的所有内容并跳回菜单,c++,C++,我被这个问题困住了,我已经尝试了我能想到的一切。我的程序是一个音乐数据库,带有用于选择选项的菜单 我有一个读取数据的功能,可以向数据库中添加一首新歌。我的cin.get声明似乎起了作用,它回应了正确的信息。但我一到最后一道菜,它就直接跳回到菜单上。我在这段代码后面放了一些伪cout语句,它们永远不会执行 这是我遇到问题的函数。如果需要,我可以发布程序的其余部分。我真的非常感谢你的帮助。我打赌这是一件非常简单的事情,我只是一个初学者,不知道问题出在哪里 提前感谢您的帮助 void inputNew

我被这个问题困住了,我已经尝试了我能想到的一切。我的程序是一个音乐数据库,带有用于选择选项的菜单

我有一个读取数据的功能,可以向数据库中添加一首新歌。我的cin.get声明似乎起了作用,它回应了正确的信息。但我一到最后一道菜,它就直接跳回到菜单上。我在这段代码后面放了一些伪cout语句,它们永远不会执行

这是我遇到问题的函数。如果需要,我可以发布程序的其余部分。我真的非常感谢你的帮助。我打赌这是一件非常简单的事情,我只是一个初学者,不知道问题出在哪里

提前感谢您的帮助

void inputNew(songType songs[], int &numSongs)
{
    char songName[100];
    char artist[100];
    int min;
    int sec;
    char album[100];

    clearScreen();

    cout << "Enter the name of the song: ";
    cin.get(songName, 100, '\n');
    cin.ignore(100, '\n');
    cout << "You entered: " << songName << endl;

    cout << "Enter the name of the artist: ";
    cin.get(artist, 100, '\n');
    cin.ignore(100, '\n');
    cout << "You entered " << artist << endl;

    cout << "Enter the minutes: ";
    cin >> min;
    cout << "You entered " << min << "minutes" << endl;

    cout << "Enter the seconds: ";
    cin >> sec;
    cin.ignore(100, '\n');
    cout << "You entered " << sec << "seconds" << endl;

    cout << "Enter the album name: ";
    cin.get(album, 100, '\n');
    cin.ignore(100, '\n');

    cout << "testing" << endl;
在您发布的注释中,main有一个while循环

while (answer != 'q')
{
    displayMenu(songs, answer, numSongs);
    processRequest(songs, answer, numSongs); // Internally calls inputNew
}

displayMenu清除屏幕并写入菜单。如果您没有以某种方式中断执行,您将无法看到processRequest编写的文本。您需要在所有输出之后添加一个std::cin.get,就像在processRequest的末尾一样。如果需要,您可以添加一条消息,如按enter继续。。。就在std::cin.get之前。

欢迎来到堆栈溢出。请阅读,采取,阅读,以及。另外,请学习如何创建一个演示。最后,请学习如何使用调试器在监视变量及其值时逐个语句地逐步调试代码。«dummy cout»cout这样使用是否正确?如果cin.fail,您不能使用透明屏幕。可以在程序的另一部分调用它并隐藏输出吗?我在程序中的一些地方有clearScreen。我试着评论他们,但我仍然有同样的问题。绝对没有必要因为某人试图发布一个潜在的解决方案而责骂他。也许可以讨论一下方法,但如果不是建设性的,就用当前的语气。谢谢你的建议。但是,它仍然不起作用:您使用的是什么编译器?Lax9999:但是,如果您还不能发表评论,并且您还不清楚某个问题,请关注另一个清楚的问题,直到您有足够的代表发表评论为止。这可以作为一个答案,即使它是一个错误的答案。张贴正确和有用的答案会让你更快地获得必要的声誉积分。