我正在尝试创建一个名称与字符串类型变量绑定的文件,但是,当我尝试运行它时,出现此错误-[Error]没有匹配到对'((std :: ofstream {aka std ::: basic_ofstream})(const char *)'
这里是代码:
void Crear()
{
string nombre;
ofstream output;
ifstream input;
cout << "Deme el nombre de su archivo: ";
cin.ignore();
getline(cin, nombre);
//this is where the error happens
output(nombre.c_str());
}
您应该尝试使用ostream
的输出运算符:
output << nombre;
无论如何,您的ofstream output;
没有与任何文件名关联。