// fileread.cpp CIS 205 C/C++ 04/17/2002
// this program reads the contents of a disk file
/* Sample output
Oranges
Apples
Bananas
Pears
Done reading C:\temp\fruitbowl.txt
Press any key to continue
*/
#include <iostream.h>
#include <fstream.h>
#define FILENAME "C:\\temp\\fruitbowl.txt"
void readFile(ifstream);
int main(void)
{
ifstream myInputFileStream;
myInputFileStream.open(FILENAME);
if(myInputFileStream != NULL)
{
// all's ok
readFile(myInputFileStream);
cout << endl << "Done reading " << FILENAME << endl;
}
else
{
cout << "Could not open " << FILENAME << endl;
}
myInputFileStream.close();
return 0;
}
void readFile(ifstream inputFile)
{
char chrFileCharacter;
while(!inputFile.eof())
{
inputFile.get(chrFileCharacter);
cout << chrFileCharacter;
}
}