ファイルから情報を取得する際に文字列リテラルを含める方法に関する質問があります。私はより良い理解のために自分のコードをお見せしましょう:文字リテラルを含めるには?
Program.b:
print \"Hello World\n\"; print \"Commo Estas :)\n\"; print \"Bonjour\";print \"Something\"; return 0;
main.cppに(私はこの質問のために必要とされるものに実際のファイルを最小化している):
int main()
{
std::string file_contents;
std::fstream file;
file.open("Program.b");
std::ifstream file_read;
file_read.open("Program.b");
if(file_read.is_open())
while(getline(file_read,file_contents));
cout << file_contents << endl;
}
私はfile_contents
を印刷するときに、今、私が手:
print \"Hello World\n\"; print \"Commo Estas :)\n\"; print \"Bonjour\";print \"Something\"; return 0;
\n
が含まれていることがわかります。それを実際の文字リテラルにする方法はありますか?それで、実際に印刷すると新しい行が印刷されますか? (私は引用符のために同じことをしたいと思う)
実行時にファイルを読む必要がありますか?それ以外の場合は、おそらくプリプロセッサを使用する可能性があります。 –
いいえ、@πάνταῥεneedは必要ありません。私はプリプロセッサを使うことができますか? .. #define toStr(x)#x'? – amanuel2
あなたが望むことをするリンクがあります:[リンク](http://stackoverflow.com/questions/5612182/convert-string-with-explicit-escape-sequence-into-relative-character) – Rikocar