How to use map (STL)?-
来源:互联网 发布:软件开发日程表 编辑:程序博客网 时间:2024/05/21 22:02
The following code demonstrates how to use the map<string, int>
to count occurrences of words. It uses the word as the key and the count as the value.
#include <iostream>#include <string>#include <map> int main(){ std::map<std::string, int> wordcounts; std::string s; while (std::cin >> s && s != "end") ++wordcounts[s]; while (std::cin >> s && s != "end") std::cout << s << ' ' << wordcounts[s] << '\n';}
The following code demonstrates how to use the map<string, int>
insert function to construct index.
#include <iostream>#include <map>#include <string>using namespace std;typedef map<string,int>::value_type pairDict;int main(){map<string,int> dict;char name[100];int i=0;while(EOF!=scanf("%s",name)){dict.insert(pairDict(string(name),i++));}return 0;}
- How to use map (STL)?-
- How To Use DataGird
- how to use typedef
- how to use gz
- How to use chkconfig
- How to use ,,,,
- how to use dialog
- How to use UIDs
- How to use dmalloc
- How to use abld
- How to use BSTR
- How to use Ant
- how to use mstsclib
- how to use gcc
- how to use thread
- how to use ffmpeg
- How to use RDebug
- How to use regex
- 抽象类和接口的区别,例子经典
- 豆瓣FM-Hacker——豆瓣FM播放列表补全计划
- Strategy学习笔记
- 2011年9月的困惑
- 小菜鸟报道
- How to use map (STL)?-
- DOS显示320*200 256色位图
- 乔布斯辞职 苹果向右Google向左
- PCB各层含义
- VC++ 的类中使用函数指针的小例子,通过函数指针调用不同的函数
- HCI Blog
- 用java实现一个哈希表类
- java中的枚举
- Cannot connect virtual device floppy0