Ofstream 拒绝带有参数的输入

Ofstream rejects input with parameters

本文关键字:输入 参数 拒绝 Ofstream      更新时间:2023-10-16

我正在为学校项目工作,我必须在 txt 文件中写入一些行。没有什么不寻常的,但问题来了。当我尝试通过函数中的参数输入输出文件名时,它说没有匹配的函数可供调用。让我向您展示我的代码:

bool save(vector<City*> city, string output){
   ofstream dat(output); // ... here comes the problem
}  

如果有人知道这里有什么问题以及如何使其工作,我将非常高兴。谢谢

您必须启用-std=c++11编译器选项,或使用ofstream dat(output.c_str());

请参阅可用std::ofstream结构器的参考文档。