I have this code:
try{
ifstream file("Students.txt", ios::in);
if (!file) throw MyExceptions();
int begin = file.tellg();
file.seekg (0, ios::end);
int end = file.tellg();
int size = end - begin;
char *charField;
int numFields = 0, charNumber = 0;
CustomString studentCode, secondName, firstName;
while (file.getline(charField, size, ',')) {
while(*charField == ','){
charNumber++;
charField++;
}
int tmpCharNumber = charNumber;
while(tmpCharNumber > 0){
tmpCharNumber--;
charField--;
}
if (numFields == 0){
studentCode = CustomString(charField, charNumber);
numFields++;
}else if (numFields == 1){
secondName = CustomString(charField, charNumber);
numFields++;
}else if (numFields == 2){
firstName = CustomString(charField, charNumber);
numFields = 0;
}
firstName.PrintData();
secondName.PrintData();
studentCode.PrintData();
}
file.close();
}catch(MyExceptions e){
}
And this file:
SR000001,EPONYMO 0001,ONOMA 0001 SR000002,EPONYMO 0002,ONOMA 0002 SR000003,EPONYMO 0003,ONOMA 0003
I get this error on the while
statement:
RUN FAILED (exit value -1,073,741,819, total time: 3s)
Any suggestion?
I do not understand where the error is? Should I use any library?