//Assuming ini.txt and input.dat both contain integer data. The 2 while
//loops each read data until the end of file is encountered (assuming all
//data in the file(s) is integer data. They illustrate two different ways
//to read data until you are out of data, i.e. at eof.
#include
#include
using namespace std;
int main()
{
ifstream infile1, infile2;
int x;
infile1.open("ini.txt");
while(!infile1.eof()) // this says to read as long as we aren't at end of file (eof)
{
cout << "in while" << endl;
infile1>>x;
cout << x;
}
infile2.open("input.dat");
while (infile2 >> x) // this says as long as we were able to read an integer from the
// file we keep going (once we get to eof there is nothing to read)
cout << x;
infile1.close();
infile2.close();
}