unsorted_map,unsorted_set如何操作 unsorted_mapunsorted_set 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // map_insert.cpp// compile with: /EHsc#include <map>#include <iostream>int main( ) { using namespace std; map <int, int>::iterator m1_pIter, m2_pIter; map <int, int> m1, m2; typedef pair <int, int> Int_Pair; m1.insert ( Int_Pair ( 1, 10 ) ); m1.insert ( Int_Pair ( 2, 20 ) ); m1.insert ( Int_Pair ( 3, 30 ) ); m1.insert ( Int_Pair ( 4, 40 ) ); cout << "The original key values of m1 ="; for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ ) cout << " " << m1_pIter -> first; cout << "." << endl; cout << "The original mapped values of m1 ="; for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ ) cout << " " << m1_pIter -> second; cout << "." << endl; pair< map<int,int>::iterator, bool > pr; pr = m1.insert ( Int_Pair ( 1, 10 ) ); if( pr.second == true ) { cout << "The element 10 was inserted in m1 successfully." << endl; } else { cout << "Key number 1 already exists in m1\n" << "with an associated value of ( (pr.first) -> second ) = " << ( pr.first ) -> second << "." << endl; } // The hint version of insert m1.insert( --m1.end( ), Int_Pair ( 5, 50 ) ); cout << "After the insertions, the key values of m1 ="; for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ ) cout << " " << m1_pIter -> first; cout << "," << endl; cout << "and the mapped values of m1 ="; for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ ) cout << " " << m1_pIter -> second; cout << "." << endl; m2.insert ( Int_Pair ( 10, 100 ) ); // The templatized version inserting a range m2.insert( ++m1.begin( ), --m1.end( ) ); cout << "After the insertions, the key values of m2 ="; for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ ) cout << " " << m2_pIter -> first; cout << "," << endl; cout << "and the mapped values of m2 ="; for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ ) cout << " " << m2_pIter -> second; cout << "." << endl;} 谢谢您的回答,map的使用我已知道,现在我需要的是vs2010版本新增的unsorted_map,unsorted_set的操作方法,还望各位大师不吝赐教,贴出unsorted_map,unsorted_set自定义主键的使用方法!! 问个if语句的意思?? 响应WM_VSCROLL消息,有没有办法判断是向上移动,还是向下移动? 为什么我设置的全局鼠标钩子只能截获当前进程的鼠标事件? 菜鸟问题:SDI中,视图用CFormView类,如何再增加一个CFormView,且能够实现切换?谢谢! 一个好问题。 如何获得滚动条句柄? 请关注 Visual Assist 软件使用问题求助啊 那里有 VC下的OutlookBar类,ActiveX控件也行? 怎样不让htmlview 对activex作安全警告? unsorted_map,unsorted_set如何操作 winpcap可以用在win7和win8吗?
// compile with: /EHsc
#include <map>
#include <iostream>int main( ) {
using namespace std;
map <int, int>::iterator m1_pIter, m2_pIter; map <int, int> m1, m2;
typedef pair <int, int> Int_Pair; m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );
m1.insert ( Int_Pair ( 4, 40 ) ); cout << "The original key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "." << endl; cout << "The original mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl; pair< map<int,int>::iterator, bool > pr;
pr = m1.insert ( Int_Pair ( 1, 10 ) ); if( pr.second == true ) {
cout << "The element 10 was inserted in m1 successfully." << endl;
}
else {
cout << "Key number 1 already exists in m1\n"
<< "with an associated value of ( (pr.first) -> second ) = "
<< ( pr.first ) -> second
<< "." << endl;
} // The hint version of insert
m1.insert( --m1.end( ), Int_Pair ( 5, 50 ) ); cout << "After the insertions, the key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "," << endl; cout << "and the mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl; m2.insert ( Int_Pair ( 10, 100 ) ); // The templatized version inserting a range
m2.insert( ++m1.begin( ), --m1.end( ) ); cout << "After the insertions, the key values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> first;
cout << "," << endl; cout << "and the mapped values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> second;
cout << "." << endl;
}
现在我需要的是vs2010版本新增的unsorted_map,unsorted_set的操作方法,
还望各位大师不吝赐教,贴出unsorted_map,unsorted_set自定义主键的使用方法!!