// fichier.cpp Utilisations des fichiers
// > lireFic: charge le contenu un fichier en mémoire
// > ecrireFic: charge une chaîne vers un fichier
// > deux classes d'exception
// auteur: R.Astier
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
#include
#include
#include
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
class ExcFichier {
public:
ExcFichier(int e) : etat(e) { }
virtual string message();
protected:
int etat;
string msg;
};
// Erreur sur fichier en lecture (entrée)
class ExcFichierE : ExcFichier {
public:
string message() {return msg; } ;
ExcFichierE(char * txt, int e): ExcFichier(e) {
msg += "* * (ExcFichierE) Fichier ";
(msg += txt) += " non accessible en lecture";
}
};
// Erreur sur fichier en sortie ou écriture
class ExcFichierS : ExcFichier {
public:
string message() {return msg; } ;
ExcFichierS(char * txt, int e): ExcFichier(e) {
msg += "* * (ExcFichierE) Fichier '";
(msg += txt) += "' ne peut pas être créé";
}
private:
int etat;
};
string lireFic(char nomFic[]) throw (ExcFichierE) {
ifstream fic(nomFic,ios::ate);
if(!fic) throw ExcFichierE(nomFic, fic.rdstate());
long taille=fic.tellg();
cout << "taille de "<< nomFic << ": "< longueur: " << txt.length() << endl;
ecrireFic(txt,"toto");
}
catch(ExcFichierE e) { cout< > > "; cin.getline( new char[80],80);
return 0;
}
//fin fichier.cpp