【问题标题】:Boost Filesystem Compile ErrorBoost 文件系统编译错误
【发布时间】:2009-12-21 03:13:21
【问题描述】:

我正在编写一些利用 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(开括号)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

【问题讨论】:

  • 你使用的是哪个版本的 boost?

标签: c++ boost compiler-errors std boost-filesystem


【解决方案1】:

basic_path::iterator 是一个双向迭代器。所以 -1 和 -2 的算术是不允许的。迭代器和整数值之间的运算符 + 和 - 是为 RandomAccessIterator 定义的。

您可以使用--来代替.end()-1。

【讨论】:

    【解决方案2】:

    您的新错误表明您的end_path_iter 没有足够的元素(应该是“递减过去开始”吗?),即您的路径比您预期的要短。

    【讨论】:

    • 啊,这就是问题所在,我不应该在paths_iterator->parent_path().end()中使用parent_path;感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    相关资源
    最近更新 更多