c++ - Boost - unordered_set 教程/示例/任何东西?

标签 c++ boost stl c++11 unordered-set

我想在项目中使用 unordered_set

但是,它的文档要么不完整,要么只是技术引用,没有示例。

任何人都可以提供处理它的在线资源的链接吗?也欢迎书籍,最好是免费的。 Google 搜索没有返回任何有值(value)的信息。

谢谢!

最佳答案

最常见用例的代码:

#include <boost/unordered_set.hpp>
using boost::unordered_set;
using std::string;
using std::cout;
using std::endl;

int main (void)
{   
    // Initialize set
    unordered_set<string> s;
    s.insert("red");
    s.insert("green");
    s.insert("blue");

    // Search for membership
    if(s.find("red") != s.end())
        cout << "found red" << endl;
    if(s.find("purple") != s.end())
        cout << "found purple" << endl;
    if(s.find("blue") != s.end())
        cout << "found blue" << endl;

    return 0;
}

输出

found red
found blue

更多信息

http://www.cplusplus.com/reference/unordered_set/unordered_set/find/

关于c++ - Boost - unordered_set 教程/示例/任何东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422893/

相关文章:

c++ - 递归地连接以 null 结尾的字符串

c++ - asio 计时器什么时候超出范围?

c++ - boost 程序选项不适用于 GLIBCXX_DEBUG

c++ - 我应该总是处理引用返回 vector 吗?

c++ - Win32 : Changing Program Icon

c++ - 如何在 Win32 应用程序中控制焦点?

C++ 静态函数和变量

c++ - 用于安全 operator[] 访问的指向成员数组的静态指针

c++ - std::stable_sort 与 std::sort

c++ - Boost.MultiArray 初学者 : How to get a 4D-Array with dynamic inner-array-sizes?