C++ STL 向量:从索引获取迭代器?

编程入门 行业动态 更新时间:2024-10-21 16:25:12
本文介绍了C++ STL 向量:从索引获取迭代器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我写了一堆代码,通过 index[] 访问 stl 向量中的元素,但现在我只需要复制向量的一个块.看起来 vector.insert(pos, first, last) 是我想要的函数......除了我只有 first 和 last 作为整数.有什么好的方法可以获得这些值的迭代器吗?

So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like vector.insert(pos, first, last) is the function I want... except I only have first and last as ints. Is there any nice way I can get an iterator to these values?

推荐答案

试试这个:

vector<Type>::iterator nth = v.begin() + index;

更多推荐

C++ STL 向量:从索引获取迭代器?

本文发布于:2023-07-30 00:32:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   索引   迭代   STL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!