The text file contains lines formatted like so:
lSdhmhlN 15479 6694.74 O
szUfGnoI 18760 5275.53 n
I'm reading the file line by line, putting its data into buffer variables, storing those variables in a TopicD object, and inserting that object into a binary search tree. Problem is that the last line of the file is being read twice so that two identical TopicD objects are created and inserted into the tree. Why?
Here's my code:
template<class ItemType>
void read( BinarySearchTree<ItemType> & tree )
{
ifstream read( FILE_NAME.c_str() );
if ( read.fail() )
die( "Error opening the file." );
string strbuff;
double dubbuff;
int intbuff;
char chbuff;
while ( !read.eof() )
{
read >> strbuff;
read >> intbuff;
read >> dubbuff;
read >> chbuff;
TopicD buff( strbuff, dubbuff, intbuff, chbuff );
tree.add(buff);
}
read.close();
}