我使用宽字符串文件流std::wofstream打开一个文件并读取其内容。我使用了头文件fstream。但是当我在XCode 7上编译这段代码时,它显示以下错误
No matching member function for call to 'open'我的代码是这样的
header used <fstream>
std::wofstream out;
out.open(filename, std::ios::binary); <--- error
* filename is wide char string注意:它与Visual Studio 2015一起在windows上工作得很好。
发布于 2016-03-03 21:37:11
std::wofstream只是一个模板类型为wchar_t的std::basic_ofstream。对于每个标准,std::basic_ofstream::open有两个重载
void open( const char *filename,
ios_base::openmode mode = ios_base::out );
void open( const std::string &filename,
ios_base::openmode mode = ios_base::out );正如你所看到的,这两种方法都不适用于wchar_t*或std::wstring。我怀疑MSVS添加了一个重载,以适应使用带有宽字符串的open,而xcode没有。
将std::string或const char*传递给open()应该没有问题
我想指出的是,没有理由先构造对象然后再调用open()。如果你想构造并打开一个文件,那么只需使用构造函数就可以了。
std::wofstream out;
out.open(filename, std::ios::binary);变成了
std::wofstream out(filename, std::ios::binary);https://stackoverflow.com/questions/35773613
复制相似问题