boost :: filesystem :: path和fopen() [英] boost::filesystem::path and fopen()
问题描述
当我尝试这样做时,我得到错误:
I get error when I try to do this:
path p = "somepath";
FILE* file = fopen(p.c_str(), "r");
我得到:
类型const boost :: filesystem :: path :: value_type *的参数与类型const char *的参数不兼容
argument of type "const boost::filesystem::path::value_type *" is incompatible with parameter of type "const char *"
有谁能告诉我我做错了什么?感谢
Could anyone tell me what I'm doing wrong? Thanks
推荐答案
如果您使用Windows, value_type
code> wchar_t ,并且在 fopen
(需要 char *
)。根据文档,似乎你必须使用 string()
方法来获取一个标准字符串与默认代码转换器 wchar_t
- > char
):
If you're under Windows, that value_type
is wchar_t
, and will fail in the conversion for fopen
(that needs a char*
). As per the documentation, it seems you have to use the string()
method to obtain a standard string with a default code conversor (wchar_t
-> char
):
FILE* file = fopen(p.string().c_str(), "r");
这篇关于boost :: filesystem :: path和fopen()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!