开发者

C++/CLi - Using streamwriter to write to text file is overwriting what's already there

开发者 https://www.devze.com 2023-02-23 22:54 出处:网络
The code I\'m using to write a string to a file is as follows: void addToWhitelist(System::String ^emailAddress)

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?


Try adding "true" as second parameter to StreamWriter constructor. (Boolean value says whether to append)

0

精彩评论

暂无评论...
验证码 换一张
取 消