Hi all,
I made the following loop to read data from a text file:
the txt file itself contains data in the following format:
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
etc....the '\n' and '@' at the end of each data is the deliminator between the four data. However, this code goes into an infinate loop for some reason. When it executes line 14, shouldn't the loop continue if there is a new data or get out of the loop since it should encounter the end of file? I tried using while (inStream.getli ne(name, 25, \n)) vs using .eof() but that resulted in only one set of data being read. Any help?
Regards,
Jthep
I made the following loop to read data from a text file:
Code:
inStream.getline(name, 25, '\n');
while(!inStream.eof())
{
inStream.getline(address, 80, '@');
inStream >> yearofbirth;
//discard newline
inStream.get();
inStream.getline(telno, 15, '\n');
//discard newline
instream.get();
addRecord(name, address, yearofbirth, telno);
records++;
inStream.getline(name, 25, '\n');
}
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
name\n
address@ (can be more than one line)
yearofbirth\n
telno\n
etc....the '\n' and '@' at the end of each data is the deliminator between the four data. However, this code goes into an infinate loop for some reason. When it executes line 14, shouldn't the loop continue if there is a new data or get out of the loop since it should encounter the end of file? I tried using while (inStream.getli ne(name, 25, \n)) vs using .eof() but that resulted in only one set of data being read. Any help?
Regards,
Jthep
Comment