Faire sortir des informations dans un fichier

Author:


Download


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

Leave a Reply

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