此部分用于擦除FDRFreq矢量项,其中数据长度小于标准数,但调试断言失败:向量迭代器不兼容。
This part is used to erase the FDRFreq vector item, in which the data length is smaller than the standard number, but the debug assertion failed: vector iterators incompatible. I am a green hand in C++ STL, thanks for your kindly help.
推荐答案您的代码需要成为
while (iter != FDRFreq.end()){ if( iter->fData.size() < StandardNum){ iter = FDRFreq.erase(iter); } else{ ++iter; } }向量迭代器不兼容重新使用已被无效 - 也就是说,不能保证它指向的元素仍然存在于该存储器位置。向量元素的擦除使该位置之后的迭代器无效。 .erase 返回一个新的,有效的迭代器,您可以改用。
"vector iterators incompatible" means that the iterator you're using has been invalidated - that is to say, there is no guarantee that the elements it points to still exist at that memory location. An erase of a vector element invalidates the iterators following that location. .erase returns a new, valid iterator you can use instead.
如果你刚接触STL,强烈建议您阅读Scott Myer的有效STL (以及 Effective C ++ )
If you're new to STL, I highly recommend you read Scott Myer's Effective STL (and Effective C++, while you're at it)
更多推荐
C ++ STL向量迭代器不兼容
发布评论