How to add valid key without specifying value to a std::map?

后端 未结 5 1181
不知归路
不知归路 2021-02-20 05:10

I have a std::map, and I would like to add a valid key to iterate over it later, but without giving any value (it will be given later on in the course of the iterations).

5条回答
  •  -上瘾入骨i
    2021-02-20 05:18

    you can try by just making a temporary float or any data type and initialize the value of the map with it.

    #include 
    #include 
    #include 
    #include 
    using namespace std;
    
     int main()
     {
     map >> hen;
    map> m;
    
    string s="egg";
    hen[s]=m;
    hen[s][1].push_back(5);
    
    
    
    
    return 0;}
    

    as you can see in this example I have made temporary map m to initialize it to hen[s] similarly, you can create a temp float to initialize it to your map.

提交回复
热议问题