2012-09-24 31 views
2

嘿,我想在一个文本文件中输出一些ascii字符,然后加载它们并将它们用于菜单。任何人都可以帮助我如何做到这一点。这里是我的代码: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.......!!!");                
     } 
} 
+6

这些都不是ASCII字符。阅读什么是ASCII,然后回到这里。 –

+0

@KerrekSB当我第一次运行带有这些字符的程序时。 t说他们是ASCII – Pendo826

+1

@ Pendo826:他们实际上是Unicode。 – MSalters

回答

3

为ASCII/UNI代码首先搜索每个字符,然后使用这些代码号创建的char *的char []串/阵列。之后,你可以使用这个字符串你想要的。 例如

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

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