Std::map is a sorted associative container that contains key-value pairs with unique keys. Values associated with keys can be changed. Maps are the associative containers that store sorted key-value pair, in which each key is unique and it can be inserted or deleted but cannot be altered. Maps are part of the C++ STL (Standard Template Library). What is use of map in C++?Ĭ++ map function. last, including the element pointed by first but not the element pointed by last. If no such element is found, the function returns last. Returns an iterator to the first element in the range [first,last) that compares equal to val. What is the use of MAP in C++?Ĭ++ map function. The primary overlap here is a vector vs a map with a size_t as the key. std::map should be used to map keys to values. Std::vector is used in situations where you would use an array in C or pre-STL C++: you want a contiguous block of memory to store values with fast constant time look-up. We can search, remove and insert in a map within O(n) time complexity. Value associated with keys can be altered. Maps contain sorted key-value pair, in which each key is unique and cannot be changed, and it can be inserted or deleted but cannot be altered. Maps are used to replicate associative arrays.
0 Comments
Leave a Reply. |