int location =2;vector<int> vec;vector<int>::iterator it=vec.begin();/..../std::advance(it,location);
代替
it= it + 5;
什么是首选/推荐方式?
解决方法 添加只适用于随机访问迭代器. std :: advance将与各种迭代器配合使用.只要你只处理迭代器到向量,它没有什么真正的区别,但是std :: advance会使你的代码更加通用(例如,你可以用一个列表来代替这个向量,而这个部分仍然可以使用).编辑:对于那些关心的人来说,标准描述了进步和距离如下(§24.3.4/ 1):
总结Since only random access iterators provIDe + and – operators,the library provIDes two function templates
advance
anddistance
. These function templates use+
and-
for random access iterators (and are,therefore,constant time for them); for input,forward and bIDirectional iterators they use++
to provIDe linear time implementations.
以上是内存溢出为你收集整理的c – 用于std :: vector std :: advance VS运算符的Advance迭代器全部内容,希望文章能够帮你解决c – 用于std :: vector std :: advance VS运算符的Advance迭代器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)