为什么c_str在这种打开(文件名)的情况下不起作用
Why is c_str not working in this open(filename) case
我以为我理解在打开文件时必须将std::字符串转换为*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 failedn";
cout << "EMN file: " << cCCA.get_EMNfn() << endl;
cout << "Press any key to exit" << endl;
ch = getchar();
return 1;
}
据我所知,事实是:
femn.open("file-foo.emn");
成功。但是
femn.open(stdEMN.c_str());
失败。
显而易见的结论是stdEMN.c_str()
的计算结果是一个不同于"file-foo.emn"
的字符串。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 获取打开文件名 - 预选上次打开不起作用
- 为什么c_str在这种打开(文件名)的情况下不起作用