Access violation reading location

Hello, I need to read this txt file but I don't understand what I'm doing wrong? Here's my reading function
IT;
Name Nameeee, IF-3/12 5 4 8 9 10 3 10
Martyb Goore, IF-3/12 5 8 9 6 3 2 8 9 10 5 6
David Swimmer, IF-3/15 5 2 4
Jason Mano, IT-3/6 6 7 10 10 10 9 10



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void Read(School & snew){
    string school, name, group;
    Student S;
    ifstream fd(CD);
    getline(fd, school, ';');

    S.SetSchool(school);
    cout << S.GetSchool() << endl;
    while(!fd.eof()){
        getline(fd, name, ',');
        fd >> ws;
        getline(fd, group, ' ');
        int Paz[Student::M];
        int kiek = 0;
        while(fd.peek()!= '\n' && !fd.eof()){
            fd >> Paz[kiek++];
        }
        fd.ignore();
    }
    fd.close();
}


Here's my Student class
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Student{
public:
    static const int M = 5;
private:
    string school, name, group;
    int *Marks; // dynamic array of student marks
    int nmax; // max size of array
    int n; // current size of array
    void IncreaseCapasity(int kiek);
public:
    Student(int nmax = 0);
    ~Student();

    void SetMarks(int mark);
    void SetSchool(string school);
    void SetName(string name);
    void SetGroup(string group);

    int GetMark(int i){return Marks[i];}
    string GetSchool(){return school;}
    string GetName(){return name;}
    string GetGroup(){return group;}
    int GetN(){return n;}
};

Student::Student(int nmax):Marks(NULL), n(n), nmax(nmax){
    if(nmax > 0){
        Marks = new int[nmax];
    }
}

Student::~Student(){
    if(Marks){
        delete [] Marks;
        Marks = NULL;
    }
}

void Student::IncreaseCapasity(int kiek){ // maybe this function is incorrect?
    if(kiek > nmax){ // if array increasing
        int *SNew = new int [kiek];
        for(int i=0; i<n; i++)
            SNew[i] = Marks[i];
        delete [] Marks;
        Marks = SNew;
        nmax = kiek;
    }if(kiek < nmax){ // if array decreasing
        int *SNew = new int [kiek];
        for(int i=0; i<kiek; i++)
            SNew[i] = Marks[i];
        delete [] Marks;
        Marks = SNew;
        n = nmax = kiek;
    }
}

void Student::SetMarks(int mark){
    if(n == nmax) IncreaseCapasity(n + M);
    Marks[n] = mark;
    n++;
}

void Student::SetSchool(string school){
    this->school = school;
}

void Student::SetName(string name){
    this->name = name;
}

void Student::SetGroup(string group){
    this->group = group;
}


when I'm reading int values fd >> Paz[kiek++]; I get this error Unhandled exception at 0x571121F8 (msvcp110d.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000D.
Last edited on
Are you sure that kiek++ never gets bigger than the size of Paz?
Topic archived. No new replies allowed.