stl - deleting elements completely from multimap (C++) -
so have multimap, key struct, , values struct.
multimap<struct, struct> multimap1;
multimap1
contains (format key
: value
)
1: random value 1 2: random value 2 3: random value 3 4: random value 4
i trying erase value , key multimap. let's want remove second entry of multimap. result should this:
1: random value 1 3: random value 3 4: random value 4
i have iterator points second value, when erase using multimap1.erase(it)
, should remove second entry (at least think should). have been reading on removing entries , multimaps , seems value removed multimap, not key. if erase second entry iterator pointing second value, (correct me if wrong):
1: random value 1 2: 3: random value 3 4: random value 4
is there way middle value result?
edit: apparently wrong. if erase, middle result. trying figure why not erasing correctly because, code segfaults when call erase. if call it->first
, returns key of element want removed. if call it->second
, returns value of key. if call multimap.erase(it)
, should remove entire thing, correct?
edit 2: in code, printed out it->first
, it->second
make sure pointer pointing correct element , was. when called multimap.erase(it)
, stopped loop , printed out remaining elements in multimap. prints first element correctly, second element printed (output compiler):
gewolfc?`6??2?x3??2??2?x 1@4?????buya????badwolfcorp1????amstykrq?4?x3??(4??3? x3planetexpress1geqp7?l???5?d?5?x5??5?d2q7?7?x3??(4??3?x3??
so obviously, not deleting correctly. running g++ 4.7 on linux.
edit 3: sorry many edits, want keep original question people can reference in future. experiment, called multimap.erase(it->first)
, worked correctly. can explain me why worked , going on here?
erase
remove whole entry (the "key-value" pair), want.
sometimes, confusion arises when talking map types since library specification defines value_type
mean "key-value" pair, not "value" (which defined mapped_type
); word "value" used interchangabley mean 1 or other.
Comments
Post a Comment