STL中的iterator配合Vector怎么用??

xinxin12375 2006-12-13 05:07:19
RT.请各位给点示例代码。
...全文
171 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sankt 2006-12-22
  • 打赏
  • 举报
回复
vector<int> the_vector;
vector<int>::iterator the_iterator;
for( int i=0; i < 10; i++ )
the_vector.push_back(i);
int total = 0;
the_iterator = the_vector.begin();
while( the_iterator != the_vector.end() )
{
total += *the_iterator;
the_iterator++;
}
cout << "Total=" << total << endl;
AI风 2006-12-22
  • 打赏
  • 举报
回复
vector<int> vec;

vec.push_back(1);
vec.push_back(2);
vec.push_back(3);

vector<int>::iterator it;
for(it = vec.begin(); it != vec.end(); ++it)
{
cout << *it << endl;
}

输出:
1
2
3
ReverseEngineering 2006-12-22
  • 打赏
  • 举报
回复
迭代器?
其实就个整数!
gooderfeng 2006-12-13
  • 打赏
  • 举报
回复
vector<T> t;
find(t.begin(), t.end(), value);
ppzine 2006-12-13
  • 打赏
  • 举报
回复
vector<string> vec;
vec.inster(string("aa"));
vector<string>::iterator it=vec.begin();
cout<<(*it).c_str()<<endl;

64,648

社区成员

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

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