vector > 的问题....

lqandlq 2008-07-18 09:29:13
vector<vector<string> > rightV;

我有一这个...
然后我想查看rightV[i].....怎么办..
...全文
138 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunhuanwen 2008-07-18
  • 打赏
  • 举报
回复
你如果想查看rightV[i]的话
由两种方法
1,
for(int j=0; j<oneV.size(); j++)
cout<<rightV[i][j]<<endl;

2, 就是使用iterator迭代器

vector<string> oneV;
vector<vector<string> > rightV;
oneV.push_back("oneV");
rightV.push_back(oneV);

vector<string>::iterator it_oneV = oneV.begin();
vector<vector<string> >::iterator it_rightV = rightV.begin();
for(; it_rightV != rightV.end(); ++it_rightV)
{
for(; it_oneV != oneV.end(); ++it_oneV)
cout<<*it_oneV<<endl;
}
lqandlq 2008-07-18
  • 打赏
  • 举报
回复
明白...结帖~~~谢谢大家
coverallwangp 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lqandlq 的回复:]
cout < < (*it)[2] < < (*it)[3] < <endl;

为什么是[2],[3]..兄弟
[/Quote]

随便写的,只是为了输出点信息
sunhuanwen 2008-07-18
  • 打赏
  • 举报
回复
对,顶8楼

3楼的意思是
你不是说查看oneV只能查看前两个字符嘛

所以他把由四个字符组成的string "aa11"的第三第四个字符输出出来
回答你 的问题。
xkyx_cn 2008-07-18
  • 打赏
  • 举报
回复
(*it)就是string类型了,[2],[3]是输出它的第3,4个字符

[Quote=引用 6 楼 lqandlq 的回复:]
cout < < (*it)[2] < < (*it)[3] < <endl;

为什么是[2],[3]..兄弟
[/Quote]
wjb_yd 2008-07-18
  • 打赏
  • 举报
回复
因为*t,也是个容器,重载了[]运算符
lqandlq 2008-07-18
  • 打赏
  • 举报
回复
cout << (*it)[2] << (*it)[3]<<endl;

为什么是[2],[3]..兄弟
xkyx_cn 2008-07-18
  • 打赏
  • 举报
回复
呵呵,你的另外一个帖子我回了,你去看看
Ijiuweiyaohul 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xkyx_cn 的回复:]
rightV[i]?
你想查看vector?


C/C++ code
vector<string> vs = rightV[i];
for (vector<string>::iterator it = vs.begin(); it != vs.end(); ++it)
{

}
[/Quote]
LZ你申请的vector<vector<string>>要做什么啊
你这个不是在给自己找麻烦啊
coverallwangp 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lqandlq 的回复:]
是这样的。.我有个vector <vector <string> > rightV;
往里面丢vector <string> oneV;
结果我查看oneV的时候发现只取到2个字符的东西...
我试试看你的方法....
[/Quote]
#include <vector>
#include <iostream>
using namespace std;

void main()
{
vector <string> a;
a.push_back("aa11");
a.push_back("bb22");
vector <vector <string> > rightV;
rightV.push_back(a);

vector<string> vs = rightV[0];
for (vector<string>::iterator it = vs.begin(); it != vs.end(); ++it)
{
cout << (*it)[2] << (*it)[3]<<endl;
}


}
lqandlq 2008-07-18
  • 打赏
  • 举报
回复
是这样的。.我有个vector <vector <string> > rightV;
往里面丢vector <string> oneV;
结果我查看oneV的时候发现只取到2个字符的东西...
我试试看你的方法....
xkyx_cn 2008-07-18
  • 打赏
  • 举报
回复
rightV[i]?
你想查看vector?


vector<string> vs = rightV[i];
for (vector<string>::iterator it = vs.begin(); it != vs.end(); ++it)
{

}

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧