map映照容器的使用

map映照容器可以实现各种不同类型数据的对应关系,有着类似学号表的功能。

今天在做并查集的训练时,就用上了map映照容器。

题目就不上了,直接讲一下用法。顺便说一下,实现过程是在C++的条件下。

#include<stdio.h>
#include<string>//不能用string.h,因为那是C的字符串函数库,而map是在C++下的
#include<iostream>
#include<map>
using namespace std;
以上是必要的头文件。



int main()
{
    char s[5];
    map<string,int>m;//string是原数据类型,int是对应数据类型
    scanf("%s",s);
    m[s]=1;//建立对应关系,同理可以不停建立下去
    return 0;
}

原文地址:https://www.cnblogs.com/ZouCharming/p/3868842.html