-1

我以为我理解在打开文件时必须将 std::string 转换为 *char ,但我遗漏了一些东西。它编译得很好,但没有打开。尝试了多种变体,但到目前为止,只有硬编码文件中的名称才有效:

//  const char * cEMN = cCCA.get_EMNfn().c_str();
//  femn.open(cEMN);  fails
//  femn.open("file-foo.emn"); works

string stdEMN;
stdEMN = cCCA.get_EMNfn();
femn.open(stdEMN.c_str());  // fails

if(!femn)
{
    cout << "Open of Original EMN file failed\n";
    cout << "EMN file: " << cCCA.get_EMNfn() << endl;
    cout << "Press any key to exit" << endl;
    ch = getchar();
    return 1;
}
4

1 回答 1

3

我认为它们的事实是:

femn.open("file-foo.emn");

成功。但

femn.open(stdEMN.c_str());

失败。

显而易见的结论是stdEMN.c_str()计算结果为不同于 的字符串"file-foo.emn"

于 2013-11-26T15:36:18.297 回答