什么是C++中<map>的等价物?

Abh*_*ngh 46 c# c++ dictionary language-comparisons visual-c++

我已经定义了一个类myComplex.我需要将它映射到整数.在C++中,我会先创建一个地图 map<myComplex,int>;

如何在C#中做这样的事情?

dal*_*lle 95

相当于将类SortedDictionary<TKey, TValue>System.Collections.Generic命名空间.

如果你不关心命令Dictionary<TKey, TValue>,那么System.Collections.Generic命名空间中的类可能就足够了.

  • @Daniel:是的,但这引出了一个问题:如果他们不关心订单,为什么他们在C++中使用'map'?他们本可以在C++中使用unordered_map(假设他们自C++ 11以来一直处于清醒状态). (5认同)
  • 如果他们不在乎顺序,“字典”就足够了,最好。 (3认同)

han*_*aad 40

std::map<Key, Value>SortedDictionary<TKey, TValue>

std::unordered_map<Key, Value>Dictionary<TKey, TValue>


The*_*ees 5

看一下System :: Collections :: Generic 中的Dictionary类

Dictionary<myComplex, int> myMap = new Dictionary<myComplex, int>();
Run Code Online (Sandbox Code Playgroud)