C++ map??????????????
???????????? ???????[ 2014/1/28 9:12:11 ] ????????c++ ???? map
????Map??c++???????????????????????????????????Щ?????н??????map???????°?????Ч??????????Щmap???????????????
????1. map?????????????
map<string ?? int >mapstring; map<int ??string >mapint;
map<sring?? char>mapstring; map< char ??string>mapchar;
map<char ??int>mapchar; map<int ??char >mapint??
????2. map????????
????map<int ??string> maplive;
????1.maplive.insert(pair<int??string>(102??"aclive"));
????2.maplive.insert(map<int??string>::value_type(321??"hai"));
????3?? maplive[112]="April";//map?м?????????????
????3??map??????????
????find()???????????????????????key????????????????????mapβ???????????
????map<int ??string >::iterator l_it;;
????l_it=maplive.find(112);
????if(l_it==maplive.end())
????cout<<"we do not find 112"<<endl;
????else cout<<"wo find 112"<<endl;
????4??map???????????
??????????112??
????map<int ??string >::iterator l_it;;
????l_it=maplive.find(112);
????if(l_it==maplive.end())
????cout<<"we do not find 112"<<endl;
????else maplive.erase(l_it); //delete 112;
????5??map?? swap???÷???
????Map?е?swap????????????е???????????????????????????
????For example??
#include <map>
#include <iostream>
using namespace std;
int main( )
{
map <int?? int> m1?? m2?? m3;
map <int?? int>::iterator m1_Iter;
m1.insert ( pair <int?? int> ( 1?? 10 ) );
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 ) );
cout << "The original map m1 is:";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter->second;
cout << "." << endl;
// This is the member function version of swap
//m2 is said to be the argument map; m1 the target map
m1.swap( m2 );
cout << "After swapping with m2?? map m1 is:";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << "." << endl;
cout << "After swapping with m2?? map m2 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 << "After swapping with m3?? map m1 is:";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << "." << endl;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11