尽管以下代码可以在 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}”
对于这个软件,我同时使用了 Boost 1.54(对于一些公共(public)库)和 Qt 4.8.4(对于使用这个公共(public)库的 UI),我用 MingW GCC 4.6.2 编译了所有东西。
我的 Windows Boost 构建似乎出于某种原因返回了 std::basic_string。如果我的评估是正确的,我会问你:我如何让 Boost 返回 std::string 的实例?顺便说一句,这可能吗?
如果我对问题的评价不好,请您提供一些解决方法。
干杯。
最佳答案
在 Windows 上,boost::filesystem 将 native 路径表示为 wchar_t
按设计 - 请参阅 documentation .这是非常合理的,因为 Windows 上的路径可以包含非 ASCII Unicode 字符。你无法改变这种行为。
请注意 std::string
只是std::basic_string<char>
,并且所有 native Windows 文件函数都可以接受宽字符路径名(只需调用 FooW() 而不是 Foo())。
关于c++ - boost::filesystem::path::native() 返回 std::basic_string<wchar_t> 而不是 std::basic_string<char>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18366306/