微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – boost :: filesystem :: path :: native()返回std :: basic_string而不是std :: basic_string

虽然以下代码Linux上编译,但我无法在Windows上编译它:
boost::filesystem::path defaultSaveFilePath( base_directory );
defaultSaveFilePath = defaultSaveFilePath / "defaultfile.name";
const std::string s = defaultSaveFilePath.native();
return save(s);

其中base_directory是类的属性,其类型是std :: string,而函数save只需要一个const std :: string&作为论点.编译器抱怨第三行代码

错误:从’const string_type {aka const std :: basic_string}’转换为非标量类型’const string {aka const std :: basic_string}’required

对于这个软件,我使用的是Boost 1.54(对于一些常见的库)和Qt 4.8.4(对于使用这个公共库的UI),我使用MingW GCC 4.6.2编译了所有内容.

似乎我的Windows Boost构建由于某种原因返回std :: basic_string.如果我的评估是正确的,我问你:我如何使Boost返回std :: string的实例?顺便说一下,有可能吗?

如果我对问题做了不好的评价,请您提供一些有关如何解决问题的见解.

干杯.

解决方法

在Windows上,boost :: filesystem通过设计将本机路径表示为wchar_t – 请参阅 documentation.这非常有意义,因为Windows上的路径可以包含非ASCII Unicode字符.你无法改变这种行为.

请注意,std :: string只是std :: basic_string< char>,并且所有本机Windows文件函数都可以接受宽字符路径名(只调用FooW()而不是Foo()).

原文地址:https://www.jb51.cc/c/114739.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐