我最近阅读的一些帖子声称for(const auto &it : vec)
与使用较长的迭代器语法for(std::vector<Type*>::const_iterator it = vec.begin(); it != vec.end(); it++)
相同。但是,我遇到this post,说他们不一样。将const auto&转换为迭代器
目前,我试图擦除for循环中的一个元素,使用后,并想知道是否有任何方法将const auto &it : nodes
转换为std::vector<txml::XMLElement*>::iterator
?
代码中的问题:
std::vector<txml2::XMLElement *> nodes;
//...
for (const auto &it : nodes)
{
//...
nodes.erase(it);
}
我敢肯定,我可以改写std::vector<txml2::XMLElement*>
作为一个常量指针,但不会喜欢,因为这个代码仅仅是在当下调试。
谢谢,这是一个巨大的帮助。最终使用'set_difference'结束了,但这让我走上了正确的道路。 – ZeroPhase