Question: Im working on recursion in c++ language and I need help dealing with big text files. I have to open a text file then read

Im working on recursion in c++ language and I need help dealing with big text files. I have to open a text file then read the contents backwords and print the contents on screen or in another txt file going backwards. The problem I am running into is stack overflow my program works on smaller files but as soon as I get a text file near 1000 kb or more my program crashs if their is any way around this Id appreciate the help. Im simply opening the text file storing into string array then calling recursion function with a base case that returns empty if no text is found, otherwise it prints the contents backwords.

Heres my code.

#include  #include  #include  using namespace std; void reverse_file(ifstream &in) { if(!in.eof()) { char ch = in.get(); reverse_file(in); cout << ch; } } int main() { string filename; cout << "Enter file name: "; cin >> filename; ifstream in(filename.c_str()); if(in.is_open()) { reverse_file(in); cout << endl; in.close(); } else { cout << "can not open " << filename << " to read" << endl; } return 0; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!