boost::文件系统中的错误,这可能吗

Bug in boost::filesystem, is this possible?

本文关键字:错误 文件系统 boost      更新时间:2023-10-16

当我试图编译以下代码时:

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
using namespace std;
int main()
{
    boost::filesystem3::path file_path("C:\Users\Art\Desktop\ASO.sln");
    boost::filesystem3::path new_path(file_path.begin(),file_path.end() - 1);
    return 0;
} 

我收到一个错误:

C:UsersMeboost_path......boost_148includeboost-1_48boostfilesystemv3path.hpp:163: error: no matching function for call to 'convert(const boost::filesystem3::path*, const boost::filesystem3::path*, boost::filesystem3::path::string_type&, const codecvt_type&)'

为什么?我认为boost::filesystem中有一个错误。

您的第二行代码有一个不需要的-1。下面是您正在调用的ctor的代码。

template <class InputIterator>
    path(InputIterator begin, InputIterator end)
    { 
      if (begin != end)
      {
        std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
          s(begin, end);
        path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, codecvt());
      }
    }

boost::filesystem::pathbegin()end()迭代器是而不是字符迭代器。它们是目录迭代器;它们对路径中的目录进行迭代。这些迭代器中的value_type本身就是包含目录的path

因此,您不能像那样从另一个path的迭代器构造path

相关文章: