Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::wofstream::open在MAC/Xcode上不工作_C++_Xcode_Macos_Osx Yosemite - Fatal编程技术网

C++ std::wofstream::open在MAC/Xcode上不工作

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

我使用宽字符串文件流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
使用了
标题
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
使用,那么是的。您可以在此处看到如何执行此操作: