// map-test
#include<string>
using namespace std ;
int i,j;
for(i=0; i<9; i++)
my_map[i] = i+2 ;
for(i=0; i<9; i++)
cout << my_map[i] << endl ;
map<int, int>::iterator itel; // 必须使用迭代器吗?
itel = my_map.find(3) ;
if(itel != my_map.end() ){
cout << "3 found " << endl;
cout << my_map[3] << endl;
}
my_map.erase(itel); // 使用迭代器删除。
itel = my_map.find(3) ;
if(itel != my_map.end() ){
cout << "3 found " << endl;
cout << my_map[3] << endl;
}
cout << "size " << my_map.size()<< endl ;
return 1;
}
#include<map>
#include<string>
using namespace std ;
int main()
{
map<int, int> my_map ; // 指名pairs的数据类型int i,j;
for(i=0; i<9; i++)
my_map[i] = i+2 ;
cout << "size " << my_map.size()<< endl ;
for(i=0; i<9; i++)
cout << my_map[i] << endl ;
map<int, int>::iterator itel; // 必须使用迭代器吗?
itel = my_map.find(3) ;
if(itel != my_map.end() ){
cout << "3 found " << endl;
cout << my_map[3] << endl;
}
my_map.erase(itel); // 使用迭代器删除。
itel = my_map.find(3) ;
if(itel != my_map.end() ){
cout << "3 found " << endl;
cout << my_map[3] << endl;
}
cout << "size " << my_map.size()<< endl ;
return 1;
}