How to access elements of a C++ map from a pointer?

后端 未结 3 1540
天命终不由人
天命终不由人 2020-12-14 15:33

Simple question but difficult to formulate for a search engine: if I make a pointer to a map object, how do I access and set its elements? The following code does not work.<

3条回答
  •  -上瘾入骨i
    2020-12-14 16:25

    map *myFruit;
    (*myFruit)["apple"] = 1;
    (*myFruit)["pear"] = 2;
    

    would work if you need to keep it as a pointer.

提交回复
热议问题