#include "stdafx.h"#include <map>#include <iostream>int _tmain(int argc, _TCHAR* argv[]){int vec[] = {
1,
2,
3,
4,
5,
6,
7,
8, 1, 1 };std::map<int, int> key_counts;for(int i = 0; i < sizeof(vec) / sizeof(int); i++)key_counts[vec[i]]++;//利用map容器key值唯一的特性,如果key不存在則新增一個,否則對已存在的計數自增for(auto iter = key_counts.begin(); key_counts.end() != iter; ++iter)std::cout << "Key:" << iter->first << " values:" << iter->second << std::endl;;return 0;}
#include "stdafx.h"#include <map>#include <iostream>int _tmain(int argc, _TCHAR* argv[]){int vec[] = {
1,
2,
3,
4,
5,
6,
7,
8, 1, 1 };std::map<int, int> key_counts;for(int i = 0; i < sizeof(vec) / sizeof(int); i++)key_counts[vec[i]]++;//利用map容器key值唯一的特性,如果key不存在則新增一個,否則對已存在的計數自增for(auto iter = key_counts.begin(); key_counts.end() != iter; ++iter)std::cout << "Key:" << iter->first << " values:" << iter->second << std::endl;;return 0;}