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

receiving a debug error when attempting to run program

本文关键字:调试 错误 试运行 程序      更新时间:2023-10-16

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

调试错误!

程序: ... user desktop punchline Program debug punchlineProgram.exe 模块: ... User Desktop Punchline Program Debug PunchlineProgram.exe

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

我试图让用户选择他们是否想听听开玩笑,运行,以及是否会根据其响应向用户输出消息的其他语句。如果我评论这些语句,则在尝试运行程序时不会收到错误。我知道我可能缺少一些简单的东西,因为我是新手。这是我到目前为止的代码:

/*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");
}

任何帮助将不胜感激!

与char进行比较时,您应该使用':char答案

if (answer == 'y') { *//this only checks for LOWER case y*
cout << "You selected Yes" << endl;
}

与字符串相比时使用"int/float/double ...您只能使用变量。

除此之外,您的 dekist in in n n hs n he n he n he n he n he n he n char n he n hs in hs in char,并且您不需要char y nor n n 。(您自己甚至从未在该代码中使用过)

我建议查看C 教程,大多数显示和解释char/string之间的不同之处,"answers"。