I'm having trouble getting integers from a file. If there is no space at the end of a file it works fine, but if there is a space after the last integer it grabs an extra junk number for some reason. This is my code so far
string fileName;
fstream file;
int fileArray[100];
int size;
cout << "Please enter the file name:";
cin >> fileName;
file.open(fileName);
if (!file)
{
cout << "File not found! Program terminating!!" << endl;
exit(1);
}
for (int i = 0; file.good(); i++)
{
file >> fileArray[i];
size++;
}