Boost::filesystem::path在Linux机器上接受wstring

boost::filesystem::path accepts wstring on linux machine

本文关键字:wstring 机器 Linux filesystem path Boost      更新时间:2023-10-16

根据boost文档,char在unix系统上用于boost::filesystem::path内部值类型。但是在linux上,下面的代码可以编译并正常工作。

const std::wstring &m_blobStore;
boost::filesystem::path dir(m_sharePath.begin(), m_sharePath.end());
cout<<dir.string(); // prints the value stored as wstring.

期望是,如果m_blobStorestring而不是wstring,那么它应该在linux机器上工作。

在文档中的path构造器部分,您可以找到:

template <class InputIterator>   path(InputIterator begin,
InputIterator end, const codecvt_type& cvt=codecvt());

Effects:在pathname中存储[begin,end]或source的内容。如果内容为通用格式,则通用格式为不可接受的操作系统的API,它们被转换为原生格式。[注:对于ISO/IEC 9945和Windows实现,通用格式已经可以作为本机格式接受,所以不需要执行泛型到本机的转换。——注意结束]

备注:如果[begin,end)或source的值类型不是value_type,则由cvt进行转换。

所以它接受wstring是正确的每个文档,它将在内部转换为value_type

请参阅文档的这一部分。

value_type是操作系统用来表示路径名的字符类型的实现定义的typedef。

描述为返回const string、const wstring、const u16string或const u32string的成员函数允许分别返回const string&、const wstring&、const u16string&或const u32string&