C ++ STL向量:从索引获取迭代器? [英] C++ STL Vectors: Get iterator from index?

查看:330
本文介绍了C ++ STL向量:从索引获取迭代器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我写了一堆代码,通过index []访问stl向量中的元素,但现在我需要复制一个向量的块。它看起来像 vector.insert(pos,first,last)是我想要的函数...除了我只有第一个和最后一个int。

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向量:从索引获取迭代器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆