I am using this code to accept a filename of a text file input from the user which will parsed line by line. It takes a line of text and assigns it to an array element "line", and goes through the entire text file until there are no more lines.
The problem I have with it is it does not function for text files with a certain number of lines. It seems to work fine for smaller text files, files with a small number of lines (something like 20-50 maybe), but does not work if there are several hundred lines. Why would this be, and how would I fix it?
Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line[1000]; int i = 0; char filename[50]; cout << "filename equals: "; cin >> filename; ifstream myfile (filename); if (myfile.is_open()) { while (myfile.good()) { getline (myfile,line[i]); i++; } myfile.close(); } else cout << "Unable to open file\n"; return 0; }