未处理的异常编译错误

Unhandled Exception compile error

#include <iostream>
#include <string>
#include <chrono>
#include <thread>

using namespace std;

// Magical paper printing Method.. dont touch. (un)
static void print(string tempString, string tempString1, int end) {
    if (((tempString != "") && (tempString1 != "") && (end == 1))) {
        cout << tempString << " " << tempString1 << endl;
    } else if (((tempString != "") && (tempString1 != "") && (end == 0))) {
        cout << tempString << " " << tempString1;
    } else if (((tempString != "") &&& (tempString1 = "") && (end == 1))) {
        cout << tempString << endl;
    } else if (((tempString != "") && (tempString1 != "") && (end == 0))) {
        cout << tempString;
    } else {
        cout << "Error: inside Pandora_Box.print(), Could not print \n";
    }
}

// A rare method from the future that stops time.
static void threadSleep(int newMilliseconds) {
    std::this_thread::sleep_for(std::chrono::milliseconds(newMilliseconds));
}

//---------------------MAIN_SCREEN-----------------------------------------
class mainScreen {
public:
    static void newScreen(); 
    static void screen();
    static void loading();
};

void mainScreen::newScreen() {
    for (int i = 0; i < 26; i++) {
        cout << " " << endl;
    }
}

void mainScreen::screen() {
    cout << "===============================================================================" << endl;
    cout << "|=====================                                   =====================|" << endl;
    cout << "|                   []===================================[]                   |" << endl;
    cout << "|                   []                                   []                   |" << endl;
    cout << "|                   []  ===============================  []                   |" << endl;
    cout << "|                   []  | --------------------------- |  []                   |" << endl;
    cout << "|                   []  | Do you want to open the box |  []                   |" << endl;
    cout << "|                   []  | --------------------------- |  []                   |" << endl;
    cout << "|___________________[]  ===============================  []___________________|" << endl;
    cout << "|===================[]++                               ++[]===================|" << endl;
    cout << "|                     []_______________________________[]                     |" << endl;
    cout << "|                       []===========================[]                       |" << endl;
    cout << "|                         []__    |---------|    __[]                         |" << endl;
    cout << "|     [--------------]      []__  |   [=]   |  __[]      [--------------]     |" << endl;
    cout << "|     |++++++++++++++|      ++[]__|=========|__[]++      |++++++++++++++|     |" << endl;
    cout << "|     [--------------]      ++                   ++      [--------------]     |" << endl;
    cout << "|                           ++                   ++                           |" << endl;
    cout << "|                           ++                   ++                           |" << endl;
    cout << "|                           ++  _______________  ++                           |" << endl;
    cout << "|                           ++__[]+++++++++++[]__++                           |" << endl;
    cout << "|                           ++[]+++++++++++++++[]++                           |" << endl;
    cout << "|                         __[]+++++++++++++++++++[]__                         |" << endl;
    cout << "|=======================[][][][][][][][]|[][][][][][][]=======================|" << endl;
    cout <<     "===============================================================================" << endl;

    string welcome_screen_var1; bool welcome_gate;

    getline(cin, welcome_screen_var1); 
    if ((welcome_screen_var1 == "yes") || (welcome_screen_var1 == "Yes")) {
        welcome_gate = true;
    } else if ((welcome_screen_var1 == "no") || (welcome_screen_var1 == "No")) {
        welcome_gate = true;
    } else {
        cout << "Error: Invalid input from -> welcome_screen_var1";
    }
}

void mainScreen::loading() {

    try {
        string loading_message[4] = { "Welcome", "Welcome to", "Welcome to    Pandora's", "Welcome to Pandora's Box" };

        threadSleep(300);
        newScreen();

        for (int j = 0; j <= 4; j++) {
            cout << "\t\t\t" << loading_message[j] << endl;
            threadSleep(600);
            newScreen();

            if (j == 4) {
                threadSleep(1000);
            }
        }
    } catch (const char* msg) {
        cout << msg << endl;
    }


}

//-------------------GAME_CORE--------------------------------------------
class gameCore {
public:
    static void gameLoop();
};

void gameCore::gameLoop() {

    // mainScreen gaemLoop Constructor
    mainScreen sc2;


    // Methods to Run
    sc2.screen();
    sc2.loading();
}

  //-----------------------------------------------------------------------------

int main() {

    // Constructors;
    mainScreen sc;
    gameCore gc;

    // Methods in chrono. Order
    gc.gameLoop();


    //====Return&pause=====
    system("pause");
    return 0;
}

当我搜索错误时,我找到了很多答案,但不是一个明确的答案,而且它们似乎只是 "their" 代码有帮助,无论如何我找不到随着时间的推移修复它的方法寻找在东西上,但无论如何都在这里。

当我编译代码(使用 visual studio 社区 C++)时,出现错误,

错误:

First-chance exception at 0x58627EA6 (msvcp120d.dll) in program.exe: 0xC0000005: Access violation reading location 0x4F377C2A.

If there is a handler for this exception, the program may be safely continued.

它运行得很好并且做了它需要做的事情,但是它弹出了这个错误,我也知道这可能与 mainScreen::Loading() 方法有关。

我是 C++ 的新手(大约 2-3 周),所以我知道的不多,如果有人可以帮助删除不必要的行或结构,那就太好了。

此外,如果有我可能没有找到的问题,并且那里有解决方案,请回复,在此先感谢..

for (int j = 0; j <= 4; j++)

必须是

for (int j = 0; j < 4; j++) 

无效mainScreen::loading()。

因此测试

if (j == 4)

那么应该是

if (j == 3)