2012-02-25 80 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