unordered_map

来源:互联网 发布:女子支付网络被刑拘 编辑:程序博客网 时间:2024/06/05 01:11

.C++11新特性,不自动排序的map    unordered_map

#include "stdafx.h"#include <conio.h>#include <iostream>#include <string>//#include <map>#include <unordered_map>using namespace std;int _tmain(int argc, _TCHAR* argv[]){unordered_map<string, size_t> word_count;string word;while (cin >> word){++word_count[word];}for (unordered_map<string,size_t>::iterator itr = word_count.begin(); itr!=word_count.end();itr++){cout << itr->first <<" occurs "<< itr->second <<((itr->second > 1)?" times":" time") <<endl;}//_getch();  //getch名字不建议使用  //获取字符,键盘输入直接退出getchar();                     //获取字符,回车后退出//system("pause");                //单纯等待return 0;}


原创粉丝点击