c++初试-容器(10)

#include<iostream>
#include<string>
#include<iterator>

#include<vector>
#include<deque>
#include<list>
#include<set>
#include<map>

using namespace std;

void test_vector();
void test_deque();
void test_list();
void test_set();
void test_multiset();
void test_map();
void test_multimap();
int main(){
	
	test_vector();
	test_deque();
	test_list();
	test_set();
	test_multiset();
	test_map();
	test_multimap();
	system("pause");
	return 0;
}

void test_multimap(){
	multimap<string,string> myMap;

	myMap.insert(map<string,string>::value_type("aaa","aaa"));
	myMap.insert(map<string,string>::value_type("aaa","aaa"));
	myMap.insert(map<string,string>::value_type("bbb","bbb"));
	myMap.insert(map<string,string>::value_type("bbb","bbb"));


	multimap<string,string>::iterator mapIter;

	for(mapIter = myMap.begin();mapIter != myMap.end();mapIter++){
		cout << mapIter->first << " " << mapIter->second << " ;";
	}
	cout << endl;
}

void test_map(){
	map<string,string> myMap;

	myMap.insert(map<string,string>::value_type("aaa","aaa"));
	myMap.insert(map<string,string>::value_type("aaa","aaa"));
	myMap.insert(map<string,string>::value_type("bbb","bbb"));
	myMap.insert(map<string,string>::value_type("bbb","bbb"));


	map<string,string>::iterator mapIter;

	for(mapIter = myMap.begin();mapIter != myMap.end();mapIter++){
		cout << mapIter->first << " " << mapIter->second << " ;";
	}
	cout << endl;
}
void test_multiset(){
	multiset<int> mset;	
	for(int i=0;i<20;i++){
		mset.insert(10);
	}

	for(multiset<int>::iterator it = mset.begin();it != mset.end();it++){
		cout << *it << " "; 
	}
	cout << endl;

}

void test_set(){
	set<int> s;
	for(int i=0;i<20;i++){
		s.insert(10);
	}

	for(set<int>::iterator it = s.begin();it != s.end();it++){
		cout << *it << " "; 
	}
	cout << endl;
	
}
void test_list(){
	list<char> li;
	for(char i='a';i<'z';i++){
		li.push_back(i);
	}

	while(!li.empty()){
		cout << li.front() << " ";
		li.pop_front();//删除第一个元素
	}
	cout << endl;
}

void test_deque(){
	deque<float> deq;
	for(int i=0;i<10;i++){
		deq.push_front(i*1.1f);
	}

	for(int i=0;i<deq.size();i++){
		cout << deq[i] << " ";
	}
	cout << endl;

}
void test_vector(){
	vector<int> v;
	for(int i=0;i<10;i++){
		v.push_back(i);
	}

	for(int i=0;i<10;i++){
		cout << v[i] << ' ';
	}
	cout << endl;
}


0 1 2 3 4 5 6 7 8 9
9.9 8.8 7.7 6.6 5.5 4.4 3.3 2.2 1.1 0
a b c d e f g h i j k l m n o p q r s t u v w x y
10
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
aaa aaa ;bbb bbb ;
aaa aaa ;aaa aaa ;bbb bbb ;bbb bbb ;
请按任意键继续. . .



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值