このコードは、c++ でファイルに書き込むために作成しました。
string Text;
ofstream Write_Test;("Write_Test.txt"); //Creating the file
Write_Test.open("Write_Test"); //Opening it for writing to, the ios::trunc at the end means it will open the file if it already exists, and overwrite any existing data with the new data.
while (Write_Test.is_open())
{
Write_Test << Text; //Write a message to the file.
}
Write_Test.close(); //Close the stream, meaning the file will be saved.
cout << "Done!";
しかし問題は、文字列の最初の単語だけをファイルに書き込んでいることです...
変数 'Text' を自分の名前に割り当てて 'Callum Holden' とすると、テキスト ファイルに Callum が書き込まれるだけですか?
誰かが私を正しい方向に向けることができますか?