a demo of vector of STL
// 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;
}