I need to have a map like this :
typedef std::map<int, float , char> Maptype ;
What is the syntax to insert and searching elements of pair in this map.
You cannot have three elements. The STL map stores a key-value pair. You need to decide on what you are going to use as a key.
If you want to insert element in std::map - use insert() function, and if you want to find element (by key) and assign some to it - use operator[].
Time complexity: k*log(n) where n is size of map, k is no. of elements inserted.
A map
can only map one key type to one data type. If the data contains 2 elements, use a struct or a std::pair
.
typedef std::map<int, std::pair<float, char> > Maptype;
...
Maptype m;
m[123] = std::make_pair(0.5f, 'c');
...
std::pair<float, char> val = m[245];
std::cout << "float: " << val.first << ", char: " << val.second << std::endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With