2009-12-21 6 views
1

J'écris du code qui utilise la bibliothèque du système de fichiers boost. Voici un extrait de mon code:Boost Filesystem Compile Error

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)); 

Types:

 
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 

je reçois une erreur de compilation:

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 

Ce code fait partie d'un programme qui fournit un script batch utilise lame.exe pour convertir les fichiers en mp3. La bibliothèque musicale il est conçu pour a le format:

root/artiste/chanson

OU

root/artiste/album/chanson

this-> m_input_path est le chemin à la racine .

Je ne sais pas si j'aborde correctement le problème. Si je le suis, comment puis-je corriger l'erreur que je reçois?

EDIT:

Mon code est maintenant:

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; 
    } 

L'erreur que je reçois est maintenant:

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

Quelle version de boost utilisez-vous? –

+0

Boost 1.41.0 - 15char –

Répondre

3

basic_path :: iterator est un itérateur bidirectionnel. Donc, l'arithmétique avec -1 et -2 n'est pas autorisée. Les opérateurs + et - entre un itérateur et une valeur entière sont définis pour un RandomAccessIterator. Au lieu d'utiliser .end()-1, vous pouvez recourir à -. Au lieu d'utiliser .end() -1, vous pouvez utiliser -.

1

Votre nouvelle erreur indique que votre end_path_iter n'a pas assez d'éléments (devrait-il être « décrément passé commencer »?), À savoir votre chemin est plus court que prévu.

+0

Ah, c'est le problème, je n'aurais pas dû utiliser le parent_path dans paths_iterator-> parent_path(). End(); Merci de votre aide. –

Questions connexes