加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – boost :: filesystem :: path :: native()返回std :: basic

发布时间:2020-12-16 05:27:30 所属栏目:百科 来源:网络整理
导读:虽然以下代码在 Linux上编译,但我无法在Windows上编译它: boost::filesystem::path defaultSaveFilePath( base_directory );defaultSaveFilePath = defaultSaveFilePath / "defaultfile.name";const std::string s = defaultSaveFilePath.native();return s
虽然以下代码在 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()).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读