I have been looking up dictionaries in C# and they seem to be highly useful, and was wondering if it is possible to use them in C++ as I have tried to search for dictionaries in C++ but there doesn't seem to be an equivalent that I can find. Is there some sort of library that I could download and include to the project or is there a function which does the same thing just with a different name.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
There is a corresponding type in STL, that's called
std::map
.It has the same basic functionality as a .NET Dictionary, but the implementation is quite different.
std::map
is internally based on a red-black tree datastructure, whileDictionary
uses a hash table internally.If you're just looking for something with the same behaviour,
std::map
will do, but if you have large amounts of data you have to be aware of the different performance characteristics.std::map is like a
Dictionary
.We can use map in C++ The basic format of using a map is -
Example -
There's
std::map
for logarithmic access time (usually based on a tree implementation) andstd::unordered_map
(since C++11) for expected constant, worst-case linear access time (usually based on a hashing implementation).