这在某些编译器上运行良好......有没有办法做到这一点,它可以正常工作而不会成为 c++11 或 c++14 上的不同编译器的问题?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void save_file() {
string file;
ofstream os;
cout << "Save As: ";
getline(cin, file, '\n');
os.open(file + ".dat");
//rest of code
}
错误:没有从 'basic_string, std::allocator >' 到 'const char *' 的可行转换
所以我用谷歌搜索,找到了一些答案,或者在这种情况下,canswers(癌症),试过了
os.open(file.c_str() + ".dat");
错误:二进制表达式的操作数无效('const char *' 和 'const char *')