欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C++ pair,map,vector简单用法

程序员文章站 2022-07-14 12:30:08
...

#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){

	pair<int,double>  p1;
	p1 = std::make_pair(1,2.5);
	cout<<p1.first<<endl<<p1.second<<endl;

	pair<int,float> p2(2,4.56);
	cout<<p2.first<<endl<<p2.second<<endl;


	vector<int> v1 ;
	v1.push_back(1);
	v1.push_back(2);
	v1.push_back(3);
	v1.push_back(4);

        v1.pop_back();//删除最后一个元素,返回void
	int begin= v1.front();//返回第一个元素的值,不删除
	cout<<begin<<endl;

	map<int,char> m1 ;
	m1[0] = 'a';
	m1[1] = 'b';
	m1[2] = 'c';
	cout<<m1[2]<<endl;
return 0;
}

//1
//2.5
//2
//4.56
//1
//c
//请按任意键继续. . .

参考:

http://blog.csdn.net/u012787116/article/details/52064168

http://blog.csdn.net/hancunai0017/article/details/7032383