mardi 3 décembre 2019

Index out of bounds when reading entries from a file

I have the following text file:

  1. DC's Legends of Tomorrow

  2. Ice Age 5: Collision Course

  3. Miss Peregrine's Home for Peculiar Children

  4. Forbidden Empire

  5. The Zero Theorem

  6. X-Men: Days of Future Past

  7. Jupiter Ascending

  8. The Mortal Instruments: City Of Bones

  9. The Age of Adaline

  10. Melancholia

Each entry has a line of blank space between them. I am trying to read through the file and save each movie into an array of strings. I am getting the error: Debug Assertion Failed! Expression: String substring out of range

Here is my code:

void readFile() {
        ifstream in_stream;
        int numberLines = 10;
        string movieName;
        int movieNum;
        string movieList[10];
        in_stream.open("input.txt"); 
        for (int i = 0; i < 10; i++)
        {
            in_stream >> movieNum >> movieName;
            movieList[i] = movieName;
        }

        in_stream.close();
    }

Aucun commentaire:

Enregistrer un commentaire