迭代器为2d矢量 [英] iterator for 2d vector

查看:155
本文介绍了迭代器为2d矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为2d向量(向量向量)创建迭代器?

How to create iterator/s for 2d vector (a vector of vectors)?

推荐答案

>不是非常清楚,我假设你的意思是一个2D向量是一个向量的向量:

Although your question is not very clear, I'm going to assume you mean a 2D vector to mean a vector of vectors:

vector< vector<int> > vvi;

然后你需要使用两个迭代器来遍历它,第一个是rows的迭代器,第二个是row中的列的迭代器:

Then you need to use two iterators to traverse it, the first the iterator of the "rows", the second the iterators of the "columns" in that "row":

//assuming you have a "2D" vector vvi (vector of vector of int's)
vector< vector<int> >::iterator row;
vector<int>::iterator col;
for (row = vvi.begin(); row != vvi.end(); row++) {
    for (col = row->begin(); col != row->end(); col++) {
        // do stuff ...
    }
}

这篇关于迭代器为2d矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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