#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;
}
当我搜索错误时,我找到了许多答案,但不是一个明确的答案,他们似乎只是帮助他们的&#34;代码,无论如何,我无法找到一种方法来解决这个问题,但是无论如何都会在这里查看。
当我编译代码时(使用visual studio community 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周),所以我不太了解,如果有人可以帮助删除不必要的行或构造,那就太好了。
如果有一个我可能没有找到的问题,并且有解决方案,请回复,并提前致谢..
答案 0 :(得分:1)
for (int j = 0; j <= 4; j++)
必须是
for (int j = 0; j < 4; j++)
in void mainScreen :: loading()。
因此测试
if (j == 4)
应该是
if (j == 3)