ma'p'ma'p'ma'p

#include<map>
#include<iostream>

using namespace std;

int main()
{
			map <int, int> m1, m2, m3;//定义仨map 
			map <int,int>::iterator m1_Iter; //map迭代器 
			
			m1.insert( pair <int, int>(1, 60 ) );
			 m1.insert( pair <int, int>(1, 50 ) );
			m1.insert ( pair <int,int> ( 2, 20 ) );
			m1.insert ( pair <int,int> ( 3, 30 ) );
			m2.insert ( pair <int,int> ( 10, 100 ) );
			m2.insert ( pair <int,int> ( 20, 200 ) );
			m3.insert ( pair <int,int> ( 30, 300 ) );
			 	map<int,int>::iterator  it; 
//			it=m1.find(2 );
//		    if(it!=m1.end())
//		    {cout<<"123456";m1.erase(it);}
			cout << "The original map m1is:";
			for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end() ; m1_Iter++ )
			cout << " "<<m1_Iter->second;
			cout << "."<< endl;
			cout<<m1[2];
			
		// (key,value)
		
			
			// This isthe member function version of swap
			// m2 is said to be theargument map; m1 the target map
//			m1.swap( m2);
//			
//			cout << "Afterswapping with m2, map m1 is:";
//			for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end() ; m1_Iter++ )
//			mapmapmapcout << " "<< m1_Iter ->second;
//			cout << "."<< endl;
//			
//			
//			cout << "After swapping with m2, mapm2 is:";
//			for ( m1_Iter = m2.begin( ); m1_Iter != m2.end(); m1_Iter++ )
//			cout << " "<< m1_Iter ->second;
//			cout << "."<< endl;
//			
//			
//			// This is the specialized template version of swap
//			swap( m1, m3 );
//			
//			cout << "Afterswapping with m3, map m1 is:";
//			for ( m1_Iter = m1.begin( ); m1_Iter != m1.end(); m1_Iter++ )
//			cout << " "<< m1_Iter ->second;
//			cout << "."<< endl;
}
posted @ 2020-03-30 11:30  小申同学  阅读(147)  评论(0编辑  收藏  举报