c – boost :: filesystem :: path :: native()返回std :: basic
虽然以下代码在
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()). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |