C++ std::wofstream::open在MAC/Xcode上不工作
我使用宽字符串文件流std::wofstream打开一个文件并读取其内容。我用的是fstream。但当我在XCode 7上编译这段代码时,它显示了以下错误C++ std::wofstream::open在MAC/Xcode上不工作,c++,xcode,macos,osx-yosemite,C++,Xcode,Macos,Osx Yosemite,我使用宽字符串文件流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 wid
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
使用了标题
std::wofstream out;
open(文件名,std::ios::binary) std::wofstream
只是一个std::basic\u of stream
,模板类型为wchar\u t
。每个标准有两个重载
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\u t*
或std::wstring
。我怀疑MSV添加了一个重载来适应使用带有宽字符串的open
,而xcode没有
将std::string
或const char*
传递到open()
我想指出,没有理由构造对象然后调用open()
。如果您想构造并打开一个文件,那么只需使用构造函数即可
std::wofstream out;
out.open(filename, std::ios::binary);
变成
std::wofstream out(filename, std::ios::binary);
那么,我应该将文件名转换为std::string吗?@Jai如果您将其作为std::wstring
使用,那么是的。您可以在此处看到如何执行此操作: