#include #include #include using namespace std; int main() { // 声明 map m_map; // 插入元素 m_map.insert(make_pair(1, "abc")); m_map.insert(pair(2,"bcd")); // 迭代器 map::iterator ite; for (ite=m_map.begin();ite!=m_map.end();ite++) { int key = ite->first; string value = ite->second; cout << key << "," << value << endl; } // map大小 int size = m_map.size(); cout << size << endl; // find 返回迭代器指向当前查找元素的位置否则返回map::end()位置 ite = m_map.find(1); cout << ite->second << endl; //迭代器刪除 ite = m_map.find(1); m_map.erase(ite); //用关键字刪除 int n = m_map.erase(1); //如果刪除了會返回1,否則返回0 // map 是否为空 bool stat = m_map.empty(); system("pause"); return 0; }
上一篇 【Python+Excel】批量操作Excel工作表和工作簿的5个实例
下一篇 线性表的顺序表示与实现1
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号