// Uppgift: Skapa en tabell över hur ofta specialtecken och siffror förekommer i en fil. // Nyckelord: kommandoradsargument, std::ifstream, std::map, cctype, iteratorer #include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { if (argc != 2) { cerr << "FEL: ange filnamn på kommandoraden!" << endl; return 1; } ifstream in(argv[1]); if ( ! in ) { cerr << "FEL: '" << argv[1] << "' kan ej öppnas!" << endl; return 1; } map freq_table; char c; while ( in.get(c) ) { if (isdigit(c) || ispunct(c)) ++freq_table[c]; } map::const_iterator i; for (i = freq_table.begin(); i != freq_table.end(); ++i) { cout << setw(5) << i->first << ": " << i->second << endl; } return 0; }