c++ - boost::filesystem::path::native() 返回 std::basic_string<wchar_t> 而不是 std::basic_string<char>

标签 c++ boost

尽管以下代码可以在 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/

相关文章:

c++ - 用于解压缩受密码保护的文件的库

c++ - 制定列出所有可能序列的算法

C++ 高分列表调试错误

c++ - 使用 boost::interprocess::shared_ptr 共享生命周期跨进程

c++ - 构建一个使用 boost 的 .cu 文件

c++ - 在 shared_ptr 集合上使用 boost.assign

c++ - 具有动态分配内存的 C++ 对象的参数传递

c++ - 比较给定宽度和高度的纵横比

c++ - boost::asio::async_write 没有完成它的任务

c++ - 在 vowpalwabbit 编译中未定义对 boost::program_options 的引用,ubuntu 16.04