c++ - Boost文件系统编译错误

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

我正在编写一些利用 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));

类型:

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

I get a compile error:

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 是 root 的路径。

我不确定我是否正确地解决了问题。如果是,我该如何解决我遇到的错误?

编辑:

我的代码现在是:

    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

最佳答案

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

除了使用 .end()-1,您可以求助于使用 --。

关于c++ - Boost文件系统编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1937968/

相关文章:

c++ - Boost序列化示例错误: symbol(s) not found for architecture x86_64

compiler-errors - 回送4.x- “Error: The connector has not been initialized.”

c# - 为什么循环不起作用?为什么在局部变量 "y"总是 int 而 s counter = 1 = int

c# - Linq 中的 Sql IN 子句等效

c++ - 使用链表确定适当的子集

c++ - 将 C++11 转换为等效的 C++98 代码

c++ - 第一个 SFML 2.1 GUI 项目崩溃

c++ - 扩展现有的 Spirit 语法(AST 和船长的问题)

C++ 事件对象

c++ - 使用带有 split_iterator 的分类器