fstream库,尝试创建具有变量名(c ++)的文件

问题描述 投票:0回答:1

我正在尝试创建一个名称与字符串类型变量绑定的文件,但是,当我尝试运行它时,出现此错误-[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());
}
c++ file fstream
1个回答
0
投票

您应该尝试使用ostream的输出运算符:

output << nombre;

无论如何,您的ofstream output;没有与任何文件名关联。

© www.soinside.com 2019 - 2024. All rights reserved.