Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Faire sortir des informations dans un fichier


Download

 
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
 
class Etudiant {
public:
  int matricule;
  char nom[80];
  double note;
public:Etudiant(int m, char *n, double nt)
  {
    matricule = m;
    strcpy(nom, n);
    note = nt;
  }
  friend ostream &operator<<(ostream &stream, Etudiant ob);
};
 
ostream &operator<<(ostream &stream, Etudiant ob)
{
  stream << ob.matricule << ' ';
  stream << ob.nom << ' ' << ob.note;
  stream << 'n';
 
  return stream;
}
 
int main()
{
  Etudiant  etudiant1(1011, "Joe", 14.5);
  ofstream outf("Etudiants.txt", ios::out | ios::binary);
 
  if(!outf)
  {
    cout << "Impossible d'écrire dans le fichier.";
    return 1;
  }
 
  outf << etudiant1<<"";
 
  outf.close();
 
  return 0;
}
----------------------------------------------------------------------------

No comments yet.

Leave a Comment