map使用方法集锦

简介:

#include <iostream>

#include <string>

#include <map>

using namespace std;

typedef map<int,string>::value_type mapTyp;

int main()

{

////用insert函数插入pair数据

//map<int,string> mapStudent;

//mapStudent.insert(pair<int,string>(1,"student_one"));

//mapStudent.insert(pair<int,string>(2,"student_two"));

//mapStudent.insert(pair<int,string>(3,"student_three"));

//map<int,string>::iterator iter;

//for (iter=mapStudent.begin();iter!=mapStudent.end();iter++)

//{

// cout<<iter->second<<endl;

//}

以上方法运行结果:

////用insert函数插入value_type数据

map<int,string> mapStudent;

mapStudent.insert(mapTyp(1,"student_one"));

mapStudent.insert(mapTyp(2,"student_two"));

mapStudent.insert(mapTyp(3,"student_three"));

map<int,string>::iterator iter;

for (iter=mapStudent.begin();iter!=mapStudent.end();iter++)

{

cout<<iter->first<<" *_* "<<iter->second<<endl;

}

以上运行结果:

system("pause");

}





本文转自 韬光星夜 51CTO博客,原文链接:http://blog.51cto.com/xfqxj/562308,如需转载请自行联系原作者

相关文章
|
存储 程序员 C++
C++中map的使用方法
map是一种使用键值对的数据结构,它允许我们使用键来查找值。map中的键必须是唯一且有序的,而值可以重复并且没有特定的顺序。 map中的数据以树结构进行组织,其中每个节点都由一个键和一个值组成。根据键的大小,节点被插入到正确的位置以保持树的有序性。这使得在map中查找值非常高效,因为我们可以使用二分查找来快速定位值。
709 0
|
存储 自然语言处理 C++
C++ STL中 set和map介绍以及使用方法
C++ STL中 set和map介绍以及使用方法
558 1
|
JavaScript 前端开发 索引
js中map的使用方法
js中map的使用方法
491 0
|
前端开发 容器
react map使用方法详解
react map使用方法详解
1251 0
|
索引 容器
Python----map,filter,reduce,zip,lambda的使用方法
Python----map,filter,reduce,zip,lambda的使用方法
324 0
|
安全 Java 数据库连接
让我们讲解一下 Map 集合遍历的方式
我是小假 期待与你的下一次相遇 ~
465 43
|
存储 前端开发 API
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
该文章详细介绍了ES6中Set和Map数据结构的特性和使用方法,并探讨了它们在前端开发中的具体应用,包括如何利用这些数据结构来解决常见的编程问题。
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
|
存储 安全 Java
java集合框架复习----(4)Map、List、set
这篇文章是Java集合框架的复习总结,重点介绍了Map集合的特点和HashMap的使用,以及Collections工具类的使用示例,同时回顾了List、Set和Map集合的概念和特点,以及Collection工具类的作用。
java集合框架复习----(4)Map、List、set

热门文章

最新文章