Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

C++: Ecrire et lire un fichier


Download

 
#include <fstream>
#include <iostream>
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;
}
----------------------------------------------------------------------------

No comments yet.

Leave a Comment