C++ 尝试运行程序时收到调试错误

C++ 尝试运行程序时收到调试错误,c++,C++,尝试运行程序的第一部分时,我收到以下调试错误: 调试错误 节目: …\user\desktop\PunchLineProgram\Debug\PunchLineProgram.exe 模块: …\user\desktop\PunchLineProgram\Debug\PunchLineProgram.exe 文件: 运行时检查失败#3-T (按“重试”调试应用程序) 我试图让用户选择是否要听笑话,运行if\else语句,根据用户的响应向用户输出消息。如果我注释掉这些语句,则在尝试运行程序时不会收

尝试运行程序的第一部分时,我收到以下调试错误:

调试错误

节目: …\user\desktop\PunchLineProgram\Debug\PunchLineProgram.exe 模块: …\user\desktop\PunchLineProgram\Debug\PunchLineProgram.exe

文件: 运行时检查失败#3-T (按“重试”调试应用程序)

我试图让用户选择是否要听笑话,运行if\else语句,根据用户的响应向用户输出消息。如果我注释掉这些语句,则在尝试运行程序时不会收到错误。我知道我可能错过了一些简单的东西,因为我是个新手。以下是我目前掌握的代码:

/*Include Section*/
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cctype>

/*Namespace Section*/
using namespace std;

/*Function Prototypes Section*/
void displayAllLines(ifstream &infile);
void displayLastLine(ifstream &infile);

/*Main section: this is the entry point of the program, which controls the flow of execution*/
int main()
{
    string file1;
    string file2;
    ifstream joke;
    ifstream punchline;
    int decision;
    char y;
    char n;

    cout << "*******************************************************************************" << endl;
    cout << setw(48) << "Punchline Program" << endl;
    cout << "*******************************************************************************" << endl;
    cout << endl;
    cout << "Welcome to the Punchline Program!" << endl;
    cout << "Are you ready to hear a joke? (y or n):  ";
    cin >> decision;

    if (decision == y)
    {
        cout << "Great! Let's get started!" << endl;
    }

    else if (decision == n)
    {
        cout << "Ah, no sense of humor, I see. Time to make like a tree and leaf (queue rimshot)!" << endl;
    }

    system("PAUSE");

}
/*包含部分*/
#包括
#包括
#包括
#包括
#包括
/*名称空间部分*/
使用名称空间std;
/*功能原型组*/
void显示所有行(ifstream和infle);
void displayLastLine(ifstream&infle);
/*主要部分:这是程序的入口点,控制执行流*/
int main()
{
字符串文件1;
字符串文件2;
ifstream笑话;
ifstream punchline;
int决策;
chary;
字符n;

cout与char比较时,应使用“”: 字符应答

if (answer == 'y') { *//this only checks for LOWER case y*
cout << "You selected Yes" << endl;
}
if(answer=='y'){*//这只检查小写的y*

解决此类问题的正确工具是调试器。在询问堆栈溢出问题之前,您应该逐行检查代码。有关更多帮助,请阅读。至少,您应该[编辑]您的问题将包括一个重现您的问题的示例,以及您在调试器中所做的观察。感谢您提供的信息,Greg!我将查找这些信息。我已更新代码以使用char answer,现在它正在工作。我感谢您的帮助!