C++ 在文本文件后追加写入字符串

下面的代码起到这样一个作用:

如果有flow.txt文件,则打开该文件,在文件中继续写入字符串;

如果没有该文件,则创建该文件并写入。

#include<string>
#include<fstream>
#include <iostream>
std::ofstream file;
if (file.bad())
{
    std::cout << "cannot open file" << std::endl;;
}
file.open("flow.txt", std::ios::app);
file << flow << "
";
原文地址:https://www.cnblogs.com/VVingerfly/p/5495892.html