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"); } 
  • one
    You have no class. getNextToken can be getNextToken to a separate file ... - Harry
  • Not well, but if much remake? I’m like to add this class, but I need to add it so that there are 3 files - Shadow of Biar
  • Yes, you can make 3 files without a class. You just write about class.cpp , which seems to hint at some class ... And so - class.cpp definition of getNextToken in class.h its declaration in class.h (which includes in main.cpp ), and everything is ready. .. - Harry
  • No, you need it with the class. But I do not know what can be changed and done here as a class - Shadow of Biar
  • @ ShadowBiara just transfer your getNextToken to a separate file. Her definition is a cast in her headline. Connect the header file to the *.cpp files - that's all. - Andrej Levkovitch

0