2012-02-25 82 views
-1

当我尝试编译此代码:boost :: filesystem中的错误,这可能吗?

#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:\Users\Me\boost_path\..\..\..\boost_148\include\boost-1_48\boost\filesystem\v3\path.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有一个错误。

+5

**总是**首先假定错误在_your_代码中。偶尔,你会错的,但通常这是正确的。 – 2012-02-25 21:23:32

+1

那么'#include '而不是单独的所有这些文件呢? – 2012-02-25 21:44:39

+0

@daknøk:因为他不想*包含所有内容。如果他不使用'directory_iterator',那么为什么浪费编译器的时间来包含它们呢? – 2012-02-25 23:36:17

回答

1

boost::filesystem::pathbegin()end()迭代器字符迭代器。它们是目录迭代器;他们迭代路径中的目录。这些迭代器的value_type自身为path,它们包含目录。

所以你不能从另一个path的迭代器构造path这样的迭代器。

+0

#尼科尔,好,谢谢 – smallB 2012-02-26 10:42:40

2

您的第二行代码有一个-1,其中不需要。以下是您打电话给您的代码。

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()); 
     } 
    } 
+0

-1与它无关。 – 2012-02-25 23:35:03