首页 > 其他 > 详细

a demo of vector of STL

时间:2017-02-25 15:56:02      阅读:194      评论:0      收藏:0      [点我收藏+]

 

 

// Practice1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void printArray(vector<int> vec)
{
vector<int>::iterator it = vec.begin();//call the iterator of vector
while(it != vec.end())
{
cout<<*it<<" ";//print each element, separate by one space
it++;
}
cout<<endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
vector<int> vec;
vec.push_back(5);
vec.push_back(3);
vec.push_back(13);

cout<<vec.at(1)<<endl;//get one element randomly

printArray(vec);
sort(vec.begin(), vec.end());//sort the vector
printArray(vec);

return 0;
}

a demo of vector of STL

原文:http://www.cnblogs.com/liuzc/p/6441808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!