您的位置:首页 > 编程语言 > C语言/C++

C++ vector 的简单用法

2016-05-11 17:23 477 查看
C++ vector 的简单用法

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


using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

vector SS;

SS.push_back("The number is 10");
SS.push_back("The number is 20");
SS.push_back("The number is 30");

cout << "Loop by index:" << endl;

int ii;
for (ii = 0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}

cout << endl << "Constant Iterator:" << endl;

vector<string>::const_iterator cii;
for (cii = SS.begin(); cii != SS.end(); cii++)
{
cout << *cii << endl;
}

cout << endl << "Reverse Iterator:" << endl;

vector<string>::reverse_iterator rii;
for (rii = SS.rbegin(); rii != SS.rend(); ++rii)
{
cout << *rii << endl;
}

cout << endl << "Sample Output:" << endl;

cout << SS.size() << endl;
cout << SS[2] << endl;

swap(SS[0], SS[2]);
cout << SS[2] << endl;

return 0;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: