I decided to get into some coding using class, havn't done this in a while. First up I got all these weird (to me) errors, and I'm sure its something stupid i'm doing. The source is attatched.
Thanks.
I decided to get into some coding using class, havn't done this in a while. First up I got all these weird (to me) errors, and I'm sure its something stupid i'm doing. The source is attatched.
Thanks.
Firstly, you cant declare a varibale length array like this....the size of the array must be constant (like Entry entries[10];). If you want a variable length array, look at std::vector.Code:infile >> numofentries; Entry entries[numofentries]; for(int i = 0; i < numofentries; i++) { infile >> members[i].fname; infile >> members[i].lname; infile >> members[i].pnumber; infile >> members[i].address; }
Also...members[i].fname should be entries[i].fname;
That should work. You cannot declare an array the way you did, you must use a constant.Code:#include <iostream.h> #include <fstream.h> #include "member.h" int main () { int numofentries; ifstream infile("data.txt", ios::in); infile >> numofentries; Entry* members = new Entry[numofentries]; for(int i = 0; i < numofentries; i++) { infile >> members[i].fname; infile >> members[i].lname; infile >> members[i].pnumber; infile >> members[i].address; } cout << numofentries; delete [] members; return 0; }