gpt4 book ai didi

c++ - 我的算法只将第一个字写入文件?

转载 作者:行者123 更新时间:2023-11-28 07:24:58 25 4
gpt4 key购买 nike

<分区>

我用 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 写入文本文件?

谁能指出我正确的方向?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com