std::map question

R

Razmig K

Dear mates,

Is there an elegant way to ensure the existence of a certain key among
the keys of a map variable ?

Thank you.

//rk
 
D

Dave Theese

Could you please clarify the question a little further?

I'm tempted to say "just insert a pair that has the key you desire to be
present", but somehow I think that's probably missing your intended point...
 
M

Mike Wahler

Razmig K said:
Dear mates,

Is there an elegant way to ensure the existence of a certain key among
the keys of a map variable ?

if(the_map.find(key) == the_map.end())
the_map[key];

-Mike
 
K

Kevin Goodsell

Razmig said:
Dear mates,

Is there an elegant way to ensure the existence of a certain key among
the keys of a map variable ?

I'm not sure I understand. If you want to make sure a certain key will
exist in the map, you need only insert it. As long as you don't remove
it later, this ensures that the key will exist "among the keys in the
map variable".

If you meant to ask how one would check for the existence of a
particular key, the answer is to use the 'find()' function.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top