嘿,我想在文本文件中输出一些 ascii 字符,然后加载它们并将它们用于菜单。任何人都可以帮助我如何做到这一点。这是我的代码:
#include "MenuText.h"
#include <iostream>//To allow the use of Header files.
#include <fstream>//To allow the use of external .txt files.
using namespace std;
using std::cout;
MenuText::MenuText()
{
mText = "Default";
}
MenuText :: MenuText(string text)
{
mText = text;
}
void MenuText::print()
{
cout<< "Story= " << mText<< endl;
cout<< endl;
}
void MenuText::save(ofstream& outFile)
{
outFile<< "┏┳┳┳┳┳┳┳┳●●●●●●━┓ ┣╋╋╋╋╋╋╋┫●●●●●●●┃\n"
"┣┻┻┻┻┻┻┻┻━━−●●●●┃ ┃Marooned ™ ●●●●┏┫\n "
"┣┳┳┳┳┳┳┳┳−●●●●┏╋┫ ┣╋╋╋╋╋╋╋┫●●●●−┻┻┫\n"
"┣╋╋╋╋╋╋╋┫●●●●●●●┃ ┗┻┻┻┻┻┻┻┻●●χ " << mText<< endl;
cout<< endl;
outFile<< endl;
}
void MenuText::load(ifstream& inFile)
{
string garbage;
inFile>> garbage >> mText;
}
void MenuText::Menu()
{
cout<< "\n\t******Menu******\n\n";
cout<< "Please choose one of the following:\n";
cout<< "1 -Play Game.\n";
cout<< "2 -Exit.\n";
}
void MenuText::text()
{
ifstream text;
string line;
text.open("Text.txt");
if (text.is_open())
{
while ( text.good() )
{
getline (text,line);
cout << line << endl;
}
text.close();
}
else{
throw("The text file did not load.......!!!");
}
}