我最近閱讀的一些帖子聲稱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