Searching and Inserting in a map with 3 elements in C++

后端 未结 3 1369
情话喂你
情话喂你 2021-01-02 20:47

I need to have a map like this :

typedef std::map Maptype ;

What is the syntax to insert and searching elements of

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 21:10

    A map can only map one key type to one data type. If the data contains 2 elements, use a struct or a std::pair.

    typedef std::map > Maptype;
    ...
    Maptype m;
    m[123] = std::make_pair(0.5f, 'c');
    ...
    std::pair val = m[245];
    std::cout << "float: " << val.first << ", char: " << val.second << std::endl;
    

提交回复
热议问题