I have a program that counts the words in a file and writes to the file. Everything is done through the ordered map. It should be ordered to rewrite the map, and sort by the number of words (Int) My program:
#include <iostream>
#include <string>
#include <map>
#include <fstream>
using namespace std;
int main()
{
map <string, int> words;
ifstream in;
in.open("in.txt");
string word;
while (in >> word)
words[word]++;
ofstream out;
out.open("out.txt");
int count = 0;
map <string, int>::iterator cur;
out << "Words count:" << endl;
for (cur = words.begin(); cur != words.end(); cur++)
{
out << (*cur).first << ": " << (*cur).second << endl; count += (*cur).second;
}
return 0;
}
P.S. I'm sorry I can't work with the ordered map