include <iostream>
#include <fstream>
#include <string>
int main() {
std::string path = "C:/path/to/your/folder/data.txt"; // 指定路径和文件名
std::string data = "这里是要写入的数据";
// 创建ofstream对象
std::ofstream file(path);
// 检查文件是否成功打开
if (!file.is_open()) {
std::cerr << "无法打开文件进行写入" << std::endl;
return -1;
}
// 写入数据
file << data << std::endl;
// 关闭文件
file.close();
return 0;
}