问题描述
我一直在C#中查找字典,它们似乎非常有用,并且想知道是否可以在C ++中使用它们,因为我试图在C ++中搜索字典,但似乎没有一个相当于我可以找到。是否有某种类型的库,我可以下载并包括到项目或有一个函数,做同样的事情只是一个不同的名称。
在STL中有一个相应的类型,叫做 std :: map
。
具有与.NET词典相同的基本功能,但实现是完全不同的。 std :: map
在内部基于红黑树数据结构,而 Dictionary
在内部使用散列表。 / p>
如果你只是寻找具有相同行为的东西, std :: map
有大量的数据,你必须意识到不同的性能特点。
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.
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, while Dictionary
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.
这篇关于可以在c ++中使用字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!