I am trying to read data from a file and put that data into a link list. My problem is that even if the file is empty, my function still adds junk to my link list.
Here is the function to read from the file and add, if there is data there:
Any ideas why it reads junk in from an empty file?Code:template <class Type> void linklist<Type>::readFile (char * filename) { ifstream input_data; input_data.open(filename); if (!input_data) cout << "File could not be opened." << endl; Type chore; while (!input_data.eof()) { getline(input_data, chore); node<Type> *new_node = new node<Type>(chore); add(new_node); delete new_node; chore.erase(chore.length()); } input_data.close(); }
Thanks
Brian