Error opening a file second time
Oct 24, 2015 at 7:06pm UTC
I'm making a group of students. Three constructors are used. In CourseList constructor data is read from a file ("courses"). Program reads everything ok first time, but gives an error during second call to constructor. Any advices would be appreciated.
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
Group::Group( const char * nm, unsigned numOfStud ) {
strncpy ( grNm, nm, strlen(grNm) );
stud = new Student[numOfStud];
sz = numOfStud;
};
Student::Student() {
Date dBD;
Date dEN;
strcpy (group, "n/a" );
avgMrk =0.0;
Fullname name; /*default constructor*/
CourseList cs (COURSES); /*constructor*/
}
CourseList::CourseList (const unsigned num) {
nmOfCrs = num;
cs = new char * [nmOfCrs];
char tmp[20]= {0};
ifstream rdFrm_F_To;
rdFrm_F_To.clear();
if ( !rdFrm_F_To.is_open() )
rdFrm_F_To.open ( "/home/dimon/Documents/PROJECTS/studProj/courses" , ios_base::in );
for ( unsigned i =0; i < nmOfCrs; ++i ) {
cs[i] = new char [nmLen];
rdFrm_F_To >> tmp;
strcpy ( cs[i], tmp );
}
rdFrm_F_To.clear();
rdFrm_F_To.close();
}
As you can see, I've already tried the clear() method (found on forums, but error persists)...
Last edited on Oct 24, 2015 at 7:32pm UTC
Topic archived. No new replies allowed.