私は現在、テキストファイル(plaintext.txtという名前)をキーファイルとともにアルファベットに置き換え、暗号文を作成するプログラムを開発中です私はそれらを一緒に混ぜるためのコマンドを実行します。下記に示すように、作業コードは次のとおりです。上記のコードのためのstd :: stringstreamの出力がstd :: stringと同じに動作しない
string text;
string cipherAlphabet;
string text = "hello";
string cipherAlphabet = "yhkqgvxfoluapwmtzecjdbsnri";
string cipherText;
string plainText;
bool encipherResult = Encipher(text, cipherAlphabet, cipherText);
bool decipherResult = Decipher(cipherText, cipherAlphabet, plainText);
cout << cipherText;
cout << plainText;
出力はしかし、私は取得文字列に私の「テキスト」と「cipherAlphabet」を変換したい
fgaam
hello
の下になりますそれらの両方は異なるテキストファイルを介して。
string text;
string cipherAlphabet;
std::ifstream u("plaintext.txt"); //getting content from plainfile.txt, string is text
std::stringstream plaintext;
plaintext << u.rdbuf();
text = plaintext.str(); //to get text
std::ifstream t("keyfile.txt"); //getting content from keyfile.txt, string is cipherAlphabet
std::stringstream buffer;
buffer << t.rdbuf();
cipherAlphabet = buffer.str(); //get cipherAlphabet;*/
string cipherText;
string plainText;
bool encipherResult = Encipher(text, cipherAlphabet, cipherText);
bool decipherResult = Decipher(cipherText, cipherAlphabet, plainText);
cout << cipherText;
cout << plainText;
しかし、私がこれを行うと、出力もエラーもなくなるのですか?これで私を助けてくれる人がいますか?ありがとうございました!!あなたがtext
を抽出するために、上記のコード行を使用する場合
状態がまだ良好かどうかを確認する前に、必ず 'if(t)'をチェックしてください。 –
あなたはファイルを読んでいません。ファイルをstd :: stringに読み込んで処理してください。あなたはどのようにGoogleをすることができます。 –
@AnonMail OPは、実際には 'rdbuf()'を使ってファイルを読み込んでいます。 –