I am just trying to load a data file into an array and display it. I run it and nothing comes up on the screen. Are my arrays set the right way and set to be output the right way. Please let me know what I am missing.
int main()
{
//Declare vars
string Title[150];
int Year[150];
int Length[150];
string Media[150];
int sub = 0;
// int compares = 0;
// int passes = 0;
// int exchanges = 0;
ifstream dataIn; //declare an instance variable WITHOUT attaching an
//actual file
string filename;
cout << "Enter the data file name (and path): ";
getline(cin, filename);
//Open file
//dataIn.open("C:\\NamesAndAges.dat");
dataIn.open(filename.c_str());
if(dataIn.fail() == true) //same as if(dataIn.fail())
{
cout << "Unable to access the data file." << endl;
return 888;
}
//Load arrays with data from record
dataIn >> Title[sub] >> Year[sub] >> Length[sub] >> Media[sub];
while(dataIn.eof() == false) //same as while(!dataIn.eof())
{
sub = sub + 1;
dataIn >> Title[sub] >> Year[sub] >> Length[sub] >> Media[sub];
}
dataIn.close();
int maxElements = sub; //ACTUAL number of elements in the arrays
//that contain data
cout << "\n\nArray contents.." << endl << endl;
cout << "Title Year Length Media" << endl;
cout << "----------------------------------------------------------------------" << endl;
//Display the arrays contents
for(sub = 0; sub < maxElements; sub++)
{
cout << left << setw(25) << Title[sub]
<< setw(25) << Year[sub]
<< right << setw(10) << Length[sub] << setw(10) << Media[sub] <<endl;
}
}