I have this which reads line by line from a file:
try{
streampos begin,end;
char delimeter[3] = {',', '\n', '\0'};
int numChars = 0, tmpNumChars = 0;
int pos1 = 0, pos2 = 0, pos3 = 0, startIndex = 0;
ifstream file1("Students.txt", ios::in);
if (!file1) throw MyExceptions();
begin = file1.tellg();
file1.seekg (0, ios::end);
end = file1.tellg();
int size = end - begin;
file1.seekg(0, ios::beg);
char charField[size];
while(file1.getline(charField, size, '\n'))
{
char *tmpCharField1 = charField;
while(*tmpCharField1 != '\0'){
numChars++;
tmpCharField1++;
}
tmpNumChars = numChars;
while(tmpNumChars > 0){
tmpCharField1--;
tmpNumChars--;
}
CustomString tmpStudent(tmpCharField1, numChars);
pos1 = tmpStudent.findCharacter(&delimeter[0], startIndex);
CustomString tmpStudentCode = tmpStudent.subString(startIndex, pos1);
pos2 = tmpStudent.findCharacter(&delimeter[0], (pos1 + 1));
CustomString tmpFirstName = tmpStudent.subString((pos1 + 1), pos2);
pos3 = tmpStudent.findCharacter(&delimeter[2], (pos2 + 1));
CustomString tmpSecondName = tmpStudent.subString((pos2 + 1), pos3);
Student student(tmpStudentCode, tmpFirstName, tmpSecondName);
this->StudentVector.push_back(student);
numChars = 0;
}
file1.close();
}
It runs perfectly but I do not know how to read a file with Greek Letters:
ΔΔΔΔ1,ΔΔΔΔ2,ΔΔΔΔ3
ΔΔΔΔ4,ΔΔΔΔ5,ΔΔΔΔ6
ΔΔΔΔ7,ΔΔΔΔ8,ΔΔΔΔ9
The above is an example with the format of the file, but I have to read First Names, Second Names in Greek. Any suggestion?