Boost 文件系统编译错误
我正在编写一些利用 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
我收到编译错误:
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。 其设计的音乐库具有以下格式:
root/artist/song
OR
root/artist/album/song
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
I'm writing some code that utilizes the boost filesystem library. 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.
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.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
basic_path::iterator 是一个双向迭代器。因此不允许使用 -1 和 -2 进行算术运算。迭代器和整数值之间的运算符 + 和 - 是为 RandomAccessIterator 定义的。
您可以使用 -- 来代替使用 .end()-1。
basic_path::iterator is a bidirectional iterator. So arithmetic with -1 and -2 is not allowed. Operators + and - between an iterator and an integer value is defined for a RandomAccessIterator.
Instead of using .end()-1, you could resort to using --.
您的新错误表明您的
end_path_iter
没有足够的元素(应该是“递减过去开始”吗?),即您的路径比您预期的要短。Your new error indicates that your
end_path_iter
doesn't have enough elements (should that be "decrement past begin"?), i.e. your path is shorter than you expect.