#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 ;
请按任意键继续. . .