/* GR Word-Cout mit einem Set und der Klasse String
1998-11
*/
#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
void error(char *s, char *s2="")
{
cerr << s << ' ' << s2 << '\n';
exit(1);
}
int main(int argc, char **argv)
{
const string trennzeichen(" \t\n");
map<string,int> m;
string s;
ifstream in;
if (argc == 2) {
in.open(argv[1], ios::in);
if (!in) error("Fehler beim Lesen der Datei", argv[1]);
while(getline(in, s)){
string::size_type beg, end;
beg=s.find_first_not_of(trennzeichen);
while(beg != string::npos) {
end=s.find_first_of(trennzeichen,beg);
m[s.substr(beg,end-beg)]++;
beg=s.find_first_not_of(trennzeichen,end);
}
}
} else error("Argv: Zuwenig Argumente");
for( map<string,int>::iterator i=m.begin();
i != m.end(); ++i )
{
cout << i->first << " : " << i->second << endl;
}
return 0;
}