【发布时间】:2011-06-18 08:21:43
【问题描述】:
我正在寻找一个我可以依赖的哈希映射模板,并在我需要哈希表时使用。我试图使用 hash_map 但发现它现在已弃用。尝试使用 unordered_map,但出现以下错误-
error: #error This file requires compiler and library support for the upcoming ISO C++ s tandard, C++0x. This support is currently experimental, and must be enabled with the -s td=c++0x or -std=gnu++0x compiler options.
现在,我完全糊涂了。我一直在 Java 中使用 hashmap,它非常简单。在 C++ 中并非如此。 指导我在 C++ 中使用什么以及如何使用哈希表。
【问题讨论】:
-
嗯,许多事情在 C++ 中并不像在 Java 中那样“直截了当”。正式地,unordered_map 和 unordered_set 包含在 tr1 扩展中,因此 gnu 有可能在未激活 c++01 功能的情况下提供 c++03 实现。在这种情况下,您应该能够在包含
后使用 std::tr1::unordered_map -
我忘记了:您可能需要安装 boost。它提供了一个透明可用的 tr1 实现,包括仅基于 c++03 特性的哈希表。
标签: c++ templates stl hash hashtable