C++/CLi - 使用流编写器写入文本文件会覆盖已有的内容
我用来将字符串写入文件的代码如下:
void addToWhitelist(System::String ^emailAddress)
{
StreamWriter ^pwriter = gcnew StreamWriter("whitelist.txt");
pwriter->WriteLine(emailAddress);
pwriter->Close();
}
这运行良好,但是一旦我再次运行该函数,写入文本文件的字符串就会被新值覆盖。我将如何将字符串附加到文件的新行上?
The code I'm using to write a string to a file is as follows:
void addToWhitelist(System::String ^emailAddress)
{
StreamWriter ^pwriter = gcnew StreamWriter("whitelist.txt");
pwriter->WriteLine(emailAddress);
pwriter->Close();
}
This works well, but as soon as I run the function again, the string that was written to the text file is overwritten with the new value. How would I go about appending the string to the file on a new line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将“true”添加为 StreamWriter 构造函数的第二个参数。
(布尔值表示是否追加)
Try adding "true" as second parameter to StreamWriter constructor.
(Boolean value says whether to append)