我已经编写了这段代码来写入 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写入文本文件?
谁能指出我正确的方向?