you were reading the first line of data incorrectly
CODE
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
ifstream inputFile;
string date;
string name;
double size;
inputFile.open("data.txt"); //opens the file
if (!inputFile) //test for errors
cout << "Error opening file" << endl;
else
{
//**remove getline (inputFile, date); //get a line of data
inputFile >>date>> size >> name; // ** include date
while (!inputFile.eof())
{
cout << date << "\t" << size << "\t" << name << endl; //Display next line of data found
inputFile >> date>> size>> name; // read the next value
}
cout << endl;
inputFile.close(); //close the file
}
return 0;
}
also in your data there was a space in "GoneFishing.bmp" which would cause the program to fail
if a read fails, such as
inputFile >> date>> size>> name;
it is aborted and the faulty character is left in the input stream, if you are in loop and just try to read again it will fail again and you program goes into an endless loop. You should use the functions ios::fail() or ios::good() to validate the input, e.g.
CODE
inputFile >> date>> size>> name; // read the next value
if(inputFile.fail())
{ cout << "input fail"; exit(1); }
This post has been edited by horace: 29 Oct, 2006 - 11:36 PM