Advertisement
andruhovski

STL

Feb 23rd, 2015
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. // SP-STL-02.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <iterator>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. map<int,unsigned int> statistic_map;
  13. map<int,unsigned int>::iterator m_iter;
  14. int _tmain(int argc, _TCHAR* argv[])
  15. {
  16.     ifstream file("a.txt");
  17.     istream_iterator<int> i(file);
  18.     while (i!=istream_iterator<int>())
  19.     {
  20.         int key=*i++;
  21.         m_iter=statistic_map.find(key);
  22.         if (m_iter==statistic_map.end())
  23.         {
  24.             statistic_map.insert(make_pair(key,1));
  25.         }
  26.         else
  27.         {
  28.             unsigned int n=statistic_map[key];
  29.             statistic_map[key]=n+1;
  30.         }
  31.     }
  32.    
  33.     for (m_iter=statistic_map.begin();
  34.         m_iter!=statistic_map.end(); m_iter++)
  35.     {
  36.         cout << m_iter->first << " " << m_iter->second<< endl;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement