1

boost ファイルシステム ライブラリを利用するコードを書いています。これが私のコードの抜粋です:

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

種類:

アーティストとアルバムは std::string 型です
this->find_diff は int を返します
this->m_input_path は std::string です
paths_iterator は 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 に変換するバッチ スクリプトを出力するプログラムの一部です。これが設計されている音楽ライブラリの形式は次のとおりです。

ルート/アーティスト/曲

また

ルート/アーティスト/アルバム/曲

this->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
4

2 に答える 2

3

basic_path::iterator は双方向イテレータです。したがって、-1 と -2 を使用した算術演算は許可されていません。RandomAccessIterator には、イテレータと整数値の間の演算子 + と - が定義されています。

.end()-1 を使用する代わりに、 -- を使用することもできます。

于 2009-12-21T06:19:05.680 に答える
1

あなたの新しいエラーは、end_path_iter十分な要素がないことを示しています (「decrement past begin」でしょうか?)、つまり、パスが予想よりも短くなっています。

于 2009-12-21T17:03:47.917 に答える