2

嘿,我想在文本文件中输出一些 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.......!!!");                                                             
        }
}
4

1 回答 1

3

首先搜索每个字符的 ASCII/UNI 代码,然后使用这些代码数字创建char*char[]字符串/数组。之后,您可以根据需要使用此字符串。例如

char str[5]={125,124,126,122,121};

是这些代码的链接...

于 2012-09-24T10:36:39.327 回答