我写了一个非常简单的代码,它遍历一个向量。问题是这个向量在每个迭代器上改变其大小。当矢量大小发生变化时,对std :: vector进行迭代。 (C++)
的载体是一类的专用变量。代码如下所示:
std::vector<boost::filesystem::path> headerVector;
循环是同一类的成员函数中的for循环。
看来,直到达到这个数字的for循环读取矢量大小迭代一次,然后,但矢量增加它在某些迭代(不是无限的)的大小。
我怎样才能使迭代,直到IT的价值和向量的当前大小相等?
的代码是这样的:
void HeaderObtainer::mapIterator(boost::filesystem::path aPath)
{
bool exist;
std::vector<boost::filesystem::path>::iterator it; //iterator for boost path.
for (it = headerVector.begin(); it!= headerVector.end(); it++) // For each?
{
aPath = *it;
exist = HeaderSources::fileExists(aPath); //Returns bool.
fileSearch (exist, aPath);
}
}
谢谢!
迭代器的载体不一定有效。 – JoshG79
你的意思是有*另一个*线程修改你的矢量'headerVector' **而你正在迭代它? –
你可以使用索引来代替'iterator'。 – Jarod42