Ascii代码输出?需要解决方案

时间:2012-09-24 09:58:25

标签: c++ file-io menu

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

1 个答案:

答案 0 :(得分:3)

首先搜索每个字符的ASCII / UNI代码,然后使用这些代码编号创建 char * char [] 串/阵列。之后,您可以根据需要使用此字符串。 e.g。

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

Here是这些代码的链接......