I'm trying to write a recursive function that does some formatting within a file I open for a class assignment. This is what I've written so far:
const char * const FILENAME = "test.rtf";
void OpenFile(const char *fileName, ifstream &inFile) {
inFile.open(FILENAME, ios_base::in);
if (!inFile.is_open()) {
cerr << "Could not open file " << fileName << "\n";
exit(EXIT_FAILURE);
}
else {
cout << "File Open successful";
}
}
int Reverse(ifstream &inFile) {
int myInput;
while (inFile != EOF) {
myInput = cin.get();
}
}
int main(int argc, char *argv[]) {
ifstream inFile; // create ifstream file object
OpenFile(FILENAME, inFile); // open file, FILENAME, with ifstream inFile object
Reverse(inFile); // reverse lines according to output using infile object
inFile.close();
}
The question I have is in my Reverse() function. Is that how I would read in one character at a time from the file? Thanks.