lundi 16 mai 2022

getline unreliable on macOS?

as a school project I have to code a video game with SDL2, imgui and SFML and I'm facing a really weird problem :

getline seems unreliable on macOS but not on linux

Let me explain, when I compile and run my code, I am able to read my configuration file properly and display the data on screen : it is working everytime on my linux computer but on my macbook it is working like 1 time out of 5.

My configuration file :configuration file

how the information is supposed to be displayed (working properly on linux but not everytime on macOS) : how it is when it works

The code :

    // Récupération des derniers paramètres
    std::ifstream fichierSauvegardeR ("data/save.txt");
    if (fichierSauvegardeR.is_open())
    {
      getline(fichierSauvegardeR, strNbDes);
      strcpy(buf_nb_des, strNbDes.c_str());

      getline(fichierSauvegardeR, strNbJoueurs);
      strcpy(buf_nb_joueurs, strNbJoueurs.c_str());

      // getline(fichierSauvegardeR, strNomJoueur);
      // strcpy(noms_joueurs[0], strNomJoueur.c_str());

      for (int i = 0; i < nbJoueurs; i++) {
        if(!getline(fichierSauvegardeR, strNomJoueur))
        {
          break;
        }
        else
        {
          strcpy(noms_joueurs[i], strNomJoueur.c_str());
        }
      }
      fichierSauvegardeR.close();

    }

Note that, the first 2 lines of the configuration file are always properly read (even on macOS), what doesn't work is the other lines (I've tried replacing the "\n" by std::endl and it didn't changed anything)

Aucun commentaire:

Enregistrer un commentaire