Been a long time since I coded but i started school today and here is my problem. Basically theres some file which called words.txt that you have to read from. You must count the number of words and then display the actual file. This is my code.
The problem is this: It reads the # of words fine. But it seems like it gets stuck w/ reading the file b/c afta that it doesnt display the file. But i kno my function for displayin the file works b/c i tried commenting out the first function and it displays the file the right away. Im guessing its having some difficulty with returning to the starting position... any help is appreciated.Code:#include <iostream> #include <fstream> #include <string> using namespace std; int CountTxt(ifstream&); void DispTxt(ifstream&); int main() { ifstream infile; infile.open("words.txt"); if (!infile){ cerr << "Error reading words.txt \n"; exit(1); system("pause"); } cout<< "There total number of words are: " << CountTxt(infile) << endl; infile.seekg(0); cout << "The text from the file was: \n\n"; DispTxt(infile); infile.close(); system("pause"); return 0; } int CountTxt(ifstream& in){ string s; unsigned int count(0); while (in >> s){ count++; } return count; } void DispTxt(ifstream& in){ char c; in >> noskipws; while (in >> c){ cout << c; } in >> skipws; }