二维向量的迭代器 [英] iterator for 2d vector

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

问题描述

如何为二维向量(向量的向量)创建迭代器?

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;

那么你需要使用两个迭代器来遍历它,第一个是行"的迭代器,第二个是该行"中列"的迭代器:

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 ...
    }
}

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

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