Help to remake the program so that it is framed as 3 files - main.cpp , class.cpp and class.h
#include <iterator> #include <iostream> #include <fstream> #include <map> #include <string> #include <cctype> using namespace std; string getNextToken(istream &in) { char c; string ans = ""; c = in.get(); while (!isalpha(c) && !in.eof()) { c = in.get(); } while (isalpha(c)) { ans.push_back(tolower(c)); c = in.get(); } return ans; } int main() { map<string, int> words; ifstream fin("123.txt"); string s; string empty = ""; while ((s = getNextToken(fin)) != empty) ++words[s]; for (map<string, int>::iterator iter = words.begin(); iter != words.end(); ++iter) cout << iter->first << ' ' << iter->second << endl; system("pause"); }
getNextTokencan begetNextTokento a separate file ... - Harryclass.cpp, which seems to hint at some class ... And so -class.cppdefinition ofgetNextTokeninclass.hits declaration inclass.h(which includes inmain.cpp), and everything is ready. .. - HarrygetNextTokento a separate file. Her definition is a cast in her headline. Connect the header file to the*.cppfiles - that's all. - Andrej Levkovitch