파일 시스템 부스트 오류를 컴파일합니다
-
20-09-2019 - |
문제
Boost FileSystem 라이브러리를 사용하는 코드를 작성하고 있습니다. 다음은 내 코드의 발췌문입니다.
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로 변환하는 배치 스크립트를 출력하는 프로그램의 일부입니다. 이 음악 도서관에는 형식이 있습니다.
뿌리/아티스트/노래
또는
루트/아티스트/앨범/노래
이-> 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
해결책
Basic_Path :: Ierator는 양방향 반복자입니다. 따라서 -1 및 -2 인 산술은 허용되지 않습니다. 연산자 + 및 - 반복자와 정수 값 사이에 randomaccessiterator에 대해 정의됩니다.
.end () -1을 사용하는 대신-사용에 의지 할 수 있습니다.
다른 팁
당신의 새로운 오류는 당신의임을 나타냅니다 end_path_iter
요소가 충분하지 않음 (감소해야합니다. 과거 시작 "?), 즉, 당신의 길은 당신이 기대하는 것보다 짧습니다.
제휴하지 않습니다 StackOverflow