I'm trying to read in a file into an array so that I could process the array into selection sort. But when I try to read in the file, I get a segmentation fault(core dumped) error. Here is my code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main()
    {
        string array[40707];
        int loop = 0;
        int loop2;
        string line;
        ifstream inFile("beowulf.txt");
        if (inFile.is_open())
        {
            while(!inFile.eof())
            {
                getline(inFile, line);
                array[loop] = line;
                loop++;
            }
            inFile.close();
        }
        else cout <<  "Unable to open file" << endl;
        for (loop2 =0; loop2 <= loop; loop2++)
            cout << array[loop2] << endl;
        return 0;
    }
 
     
    