来源:
https://zh.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream
#include <fstream>
#include <utility>
#include <string>
int main()
{
std::ofstream f0;
std::ofstream f1("test.bin", std::ios::binary);
std::string name = "example.txt";
std::ofstream f2(name);
std::ofstream f3(std::move(f1));
}
std::ofstream f1(file_path, mode)打开一个输出到test.bin的文件,后面的要求:
std::ios_base::openmode
常量 解释
app 每次写入前寻位到流结尾
binary 以二进制模式打开
in 为读打开
out 为写打开
trunc 在打开时舍弃流的内容
ate 打开后立即寻位到流结尾
string.c_str() 作用与string.data()相同