码迷,mamicode.com
首页 > 编程语言 > 详细

C++STL vector简单使用练习1

时间:2017-06-17 00:04:22      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:style   return   ges   赋值   out   stl   元素   ++   namespace   

 1 #include <iostream>
 2 #include <vector>
 3 #include <numeric>
 4 using namespace std;
 5 int main()
 6 {
 7     vector<int>v;//定义一个向量v
 8     for(int i=0;i<10;i++)
 9         v.push_back(i);//尾部元素扩张方式赋值
10     for(vector<int>::iterator it=v.begin();it!=v.end();it++)
11         cout<<*it<<" ";//输出迭代器当前位置上的元素值
12     cout<<endl;
13     cout<<accumulate(v.begin(),v.end(),0)<<endl;//统计并输出向量所有元素的和
14     return 0;
15 }

技术分享

C++STL vector简单使用练习1

标签:style   return   ges   赋值   out   stl   元素   ++   namespace   

原文地址:http://www.cnblogs.com/ECJTUACM-873284962/p/7029550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!