Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert perl map with multiple key to c++

I want to convert a code from perl to c++, and my problem is multi key map in perl! example:

perl:

$address{name}{familyName} = $someAddress;

and keys are not unique. I want similar data structure in c++ using map or ...!? also I want to search and obtain values with first key for example I want such %keys{name} in c++ .

edited: I want to know something like if any family name for special name exists or not , also name and family name together are the key and unique not each of them.

like image 533
Yadollah Avatar asked Dec 03 '25 10:12

Yadollah


1 Answers

The equivalent to %keys{name} is done with std::map. You can use the bracket operator to access elements of the map. And it conveniently inserts a new default-constructed object if you ask for a key that isn't there yet. You might be able to duplicate the multi-key map with a map of maps, e.g., std::map<std::string, std::map<std::string, std::string> >.

If your keys might have more than one value associated with them, use std::multimap instead of map.

like image 70
Michael Kristofik Avatar answered Dec 05 '25 01:12

Michael Kristofik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!