Ofstream 拒绝带参数的输入

Ofstream rejects input with parameters

我正在为学校项目工作,我必须将一些行写入 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 constuctors 的参考文档。