Stocker des infos ds un .txt avc C++

ti'Mat -  
tafiscobar Messages postés 1281 Statut Contributeur -
Bonjour,

Pourriez-vous m'expliquer comment on peut stocker des informations ds un fichier .txt en programmant en C++?

Merci

Ti'Mat

1 réponse

  1. tafiscobar Messages postés 1281 Statut Contributeur 177
     
    salut, tout bete, en ecrivant ds le fichier .
    2 façons:
    cas1
    /* j'ouvre mon fichier */
    FILE *fp = fopen(monfichier, "w");
    assert (fp != NULL);
    /* j'ecris ds mon fichier  */
    fprintf (fp, "voici mon beau texte");
    /* je ferme mon fichier, ne jamais oublier de fermer son fichier
      * avant la fin du programme
     */
    fclose (fp); 
    


    cas2
    ofstream f (mon fichier);
    if (f.isopen () ) {
          for (int i = 0; i < 4; i++)
             f << "voici mon texte ds le fichier "<<i<<endl;
          f.close ();
    }
    


    tafiscobar "lou waye def bopame"
    la nullite n'existe pas, l'ignorance oui, ah je suppose!!!
    0