I have a Store class with a method to read users of a file:
void Store::leerUsuarios(const string &nombreFichero){
ifstream fichero;
fichero.open(nombreFichero);
if (fichero.is_open()) {
string nom, mail, contrasenya;
while (!fichero.eof()) {
fichero >> nombre;
fichero >> mail;
fichero >> contrasenya;
usuarios[m_numUsuarios].setUsuarios(nombre, mail, contrasenya);
m_numUsuarios++;
}
fichero.close();
}
}
So, I have a .txt file with this:
USUARIO_NOM_1 USER_MAIL_1 USER_CONTRASENYA_1 USUARIO_NOM_2 USER_MAIL_2 USER_CONTRASENYA_2 USER_NOM_3 USER_MAIL_3 USER_CONTRASENYA_3 USER_NOM_4 USER_MAIL_4 USER_CONTRASENYA_4
The problem is that when I read it, when you finish reading user 4, you re-enter the while (! file.eof ()), should not you exit since you have finished reading it?