简体   繁体   English

Boost文件系统编译错误

[英]Boost Filesystem Compile Error

I'm writing some code that utilizes the boost filesystem library. 我正在编写一些使用boost文件系统库的代码。 Here is an excerpt of my code: 以下是我的代码的摘录:

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

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

This code is part of a program that outputs a batch script that uses lame.exe to convert files into mp3s. 此代码是程序的一部分,该程序输出使用lame.exe将文件转换为mp3的批处理脚本。 The music library this is designed for has the format: 这个音乐库的设计格式为:

root/artist/song 根/歌手/歌曲

OR 要么

root/artist/album/song 根/艺术家/专辑/歌曲

this->m_input_path is the path to root. this-> m_input_path是root的路径。

I'm not sure if I'm approaching the problem properly. 我不确定我是否正确地解决了这个问题。 If I am, how do I fix the error that I am getting? 如果我是,我该如何解决我得到的错误?

EDIT: 编辑:

My code is now: 我的代码现在是:

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

The error that I now get is: 我现在得到的错误是:

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

basic_path::iterator is a bidirectional iterator. basic_path :: iterator是一个双向迭代器。 So arithmetic with -1 and -2 is not allowed. 因此不允许使用-1和-2进行算术运算。 Operators + and - between an iterator and an integer value is defined for a RandomAccessIterator. 为RandomAccessIterator定义迭代器和整数值之间的运算符+和 - 。

Instead of using .end()-1, you could resort to using --. 而不是使用.end() - 1,你可以使用 - 。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM