私はスクリプト言語のフレームワークを開発しました。ゲームや映画などのアプリケーションのインタープリターが読み取るカスタム Hex コードを特定のファイルに出力するコンパイラーを作成しようとしています。インタープリターは 16 進数を読み取り、ループを介して操作を実行し、私の面倒な作業をほとんど行ってくれます。しかし、テキストの文字列をカスタム 16 進数にコンパイルする方法が必要です。これが私のコンパイラの例です。
#include <iostream>
#include <string>
#include <Windows.h>
#include <wincon.h>
#include <fstream>;
using namespace std;
int main(){
char egScriptpath[999];
char path[999];
char title[999];
ifstream readfile;
ofstream myfile;
int optn;
cout << "Enter the path where your *.egSCRIPT file is: " << endl;
cin.getline(egScriptpath,999);
cout << "Enter your path where you want to compile your *.egSCRIPT file: " << endl;
cin.getline(path,999);
cout << "Enter your title for your program: ";
cin.getline(title,999);
cout << endl << "Enter for your option of file extention:" << endl;
cout << " Enter 1 for .egGame :" << endl;
cout << " Enter 2 for .egMovie: ";
cin >> optn;
if(optn==1){
readfile.open((string)egScriptpath);
ofstream egMovieFile((string)path+"\\"+(string)title+".egGame");
myfile.open((string)path+"\\"+(string)title+".egGame");
while(!readfile.eof()){
if(readfile.getline("validated()",1)){
myfile << " \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" ////////////////\n"
" ////////////////\n"
" ||||||||||||||||\n"
" ||||||||||||||||\n"
" ||||||||||||||||\n"
" \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n"
" \2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\n";
}
}
myfile.close();
readfile.close();
}else if(optn==2){
readfile.open((string)egScriptpath);
ofstream egGameFile((string)path+"\\"+(string)title+".egMovie");
myfile.open((string)path+"\\"+(string)title+".egMovie");
while(!readfile.eof()){
if(readfile.getline("validated()",1)){
myfile << " \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
" ////////////////\n"
" ////////////////\n"
" ||||||||||||||||\n"
" ||||||||||||||||\n"
" ||||||||||||||||\n"
" \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n"
" \2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\n";
}
}
myfile.close();
readfile.close();
}
cout << "Compile complete" << endl;
system("pause");
return 0;
}
したがって、私がやりたいのは、if(readfile.getline("validated()",1)){} と書かれている if ステートメントにあります。たとえば。私が言っていることが明確であることを願っています。コンパイラがスクリプト ファイルで "validated()" を読み取ると、"16 進数" コードが "myfile" の変数を持つ新しいファイルに書き込まれ、ゲームや映画などのアプリケーションのインタープリターによって解釈されます。 . 何が間違っているのか、そしてそれが作成する新しいファイルに16進コードを書き込んでいない理由を知っているなら、ありがとう.