Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <cstring>
- using std::cout;
- using std::endl;
- using std::ifstream;
- using std::map;
- #include "string.h"
- int main(int argc, char* argv[])
- {
- if (argc != 2)
- {
- cout << "Usage: " << argv[0] << " filename" << endl;
- return 1;
- }
- char* filename = argv[1];
- ifstream ff(filename);
- if (ff.fail())
- {
- cout << "File " << filename << " doesn't exists!\n";
- return 2;
- }
- std::map<String, int> m;
- while (!ff.eof())
- {
- String s;
- ff >> s;
- WordIterator iter = s.split(" \t\n\"+-*/%=><\\;:.!?(){}[]");
- if (iter.getCount())
- {
- do
- {
- String w = iter.getCurrent();
- if (m.count(w))
- m[w]++;
- else
- m[w] = 1;
- }
- while (iter.moveNext());
- }
- }
- for(auto iter=m.begin(); iter != m.end(); iter++)
- {
- cout << "!" << iter->first.str <<" : "<< iter->second << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement