2009-12-21 117 views
1

我正在編寫一些利用boost文件系統庫的代碼。下面是我的代碼的摘錄:Boost Filesystem編譯錯誤

artist = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? (*(paths_iterator->parent_path().end() - 1)) : (*(paths_iterator->parent_path().end() - 2)); 
album = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? "" : (*(paths_iterator->parent_path().end() - 1)); 

類型:

 
artist and album are of type std::string 
this->find_diff returns an int 
this->m_input_path is a std::string 
paths_iterator is of type std::vector(open bracket)boost::filesystem::path>::iterator 

我得到一個編譯錯誤:

error C2039: 'advance' : is not a member of 'boost::filesystem::basic_path<String,Traits>::iterator' d:\development\libraries\boost\boost\iterator\iterator_facade.hpp on line 546 

此代碼是輸出一個批處理腳本程序的一部分使用lame.exe將文件轉換爲mp3。 這是專爲音樂庫的格式爲:

根/歌手/歌曲

OR

根/藝術家/專輯/歌曲

這個 - > m_input_path是通向根。

我不知道我是否正確地接近問題。如果我是,我該如何解決我所得到的錯誤?

編輯:

我的代碼是現在:

boost::filesystem::path::iterator end_path_itr = paths_iterator->parent_path().end(); 
    if(this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) /* For cases where: /root/artist/song */ 
    { 
     album = ""; 
     end_path_itr--; 
     artist = *end_path_itr; 
    } 
    else /* For cases where: /root/artist/album/song */ 
    { 
     end_path_itr--; 
     album = *end_path_itr; 
     end_path_itr--; <-- Crash Here 
     artist = *end_path_itr; 
    } 

的錯誤,我現在得到的是:

Assertion failed: itr.m_pos && "basic_path::iterator decrement pat begin()", file ... boost\filesystem\path.hpp, line 1444 
+0

您正在使用哪種版本的boost? – 2009-12-21 03:39:01

+0

Boost 1.41.0 - 15char – 2009-12-21 03:40:25

回答

3

的basic_path :: iterator是一個雙向迭代。所以不允許使用-1和-2進行算術運算。一個迭代器和一個整數值之間的運算符+和 - 爲RandomAccessIterator定義。

而不是使用.end() - 1,你可以訴諸使用 - 。

1

你的新錯誤表明你的end_path_iter沒有足夠的元素(應該是「遞減過去開始」?),即你的路徑比你期望的要短。

+0

啊,這就是問題所在,我不應該在paths_iterator-> parent_path()。end()中使用parent_path。謝謝你的幫助。 – 2009-12-21 17:42:16