我正在尝试将 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!";
}
谢谢你的帮助!