c++ primer multimap

来源:互联网 发布:saas云数据安全 编辑:程序博客网 时间:2024/06/03 17:15
std::multimap<std::string, std::string> authors;// 插入authors.insert(std::make_pair(std::string("test1"), std::string("aaa")));authors.insert(std::make_pair(std::string("test1"), std::string("bbb")));// 查找string search_item("test1");typedef multimap<string, string>::size_type sz_type;sz_type entries = authors.count(search_item);multimap<string, string>::iterator iter = authors.find(search_item);for(sz_type cnt = 0; cnt != entries; ++cnt, ++iter){std::cout << iter->second << std::endl;}// 查找方式二typedef multimap<string, string>::iterator authors_iter;authors_iter beg = authors.lower_bound(search_item);authors_iter end = authors.upper_bound(search_item);while(beg != end){std::cout << beg->second << std::endl;++beg;}// 查找方式三std::pair<authors_iter, authors_iter> pos = authors.equal_range(search_item);while(pos.first != pos.second){std::cout << pos.first->second << std::endl;++pos.first;}


原创粉丝点击