run time error

with this code it reads file.txt into a multidimensional array, but when i run it prints the element multiple times and program crashes, can someone help explain why?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
enum mediaType {CD, TAPE, MP3};
struct Song
{char title[20];
 char artist[20];
 mediaType medium;
 float cost;
};

#include <iostream>
#include <fstream>
#include <string>

using namespace std; 



int main()
{
    
    
    string Song[4][200];
    
    ifstream myfile;
    
    myfile.open("song.txt");
    

    
    if(!myfile) //Always test the file open.
    {
                cout<<"Error opening output file"<<endl;
                cin.get();
                return -1;
    }

    long a = 0;
    
    while(!myfile.eof())
    {            
        for(long b = 0; b < 4; b++)
        {
            
            if (b == 3)
            {
                  getline(myfile,Song[a][b],'\n');
                  break;
            }
            
            getline(myfile,Song[a][b],' ');
            
              
        }
        cout << Song[0][0] << ' ';    
        a++;
        
    }
    
    cin.get();
}


(song.txt)
Armstrong muggles C 4.99
Williams Superman T 1.99
krall S'wonderful C 3.99
Beethoven for_elise M 2.99
ponty watching_birds M 4.10
Armstrong Wild_man_blues C 4.56
Marley work T 3.10
krall love_letters C 3.79
Beethoven Romance_in_F C 2.88
krall cry_me_a_river C 3.69
ponty intuition M 4.20
Armstrong Hear_me_talking_to_ya M 4.12
Mouskouri crie T 2.10
ponty open_mind T 4.40
Marley bad_card M 3.20
Marley real_situation C 3.30
Armstrong muskrat T 4.88
Mouskouri vivants T 2.20
ponty solitude C 4.30
Last edited on
Topic archived. No new replies allowed.