cin コマンドで設定した文字列をファイルに書き込もうとしています。動作していますが、すべての文字列を書き込んでいるわけではありません。最初の空白の前のすべて。だから誰かが私が使用することを提案しました:
Write_Test << getline( Text , cin );
空白を受け入れるようにするには、タイトルにあるように getline を使用できませんか?
すべてのコード:
string Text;
cout << "Write something: ";
cin >> Text;
if (Text != "")
{
ifstream Write_Test("Write_Test.txt");//Creating the file
//Write_Test << Text; //Write a message to the file.
Write_Test << getline( Text , cin );
Write_Test.close(); //Close the stream, meaning the file will be saved.
cout << "Done!";
}
助けてくれてありがとう!