C++: Ecrire et lire un fichier

Author:


Download


#include 
#include 
using namespace std;

int main ()
{
   char info[80];
   ofstream stream_ecriture;
   // Accéder à un fichier pour l'écriture
   stream_ecriture.open("personne.txt");
   cout << "Exemple d'écriture du fichier" << endl;
   cout << "Tapez votre nom: ";
   cin.getline(info, 80);
   stream_ecriture << info << endl;
   cout << "Tapez votre prénom: ";
   cin >> info;
   cin.ignore();
   stream_ecriture << info << endl;
   stream_ecriture.close();

   //Accéder au fichier pour la lecture
   ifstream stream_lecture;
   cout << "Lecture du fichier" << endl;
   stream_lecture.open("personne.txt");
   stream_lecture >> info;
   cout << info << endl;
   stream_lecture >> info;
   cout << info << endl;
   stream_lecture.close();
   return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *