#include #include #include #include using namespace std; struct Vehicule; // prédéclaration nécessaire en raison de la dépendance croisée Vehicule <--> Personne typedef vector Garage; struct Personne { string nom; // Garage g; // mis de coté un moment vector amis; }; struct Vehicule { string modele; Personne* proprio; vector passagers; }; void afficher(ostream fichier, Garage const& g) { for (auto p_v : g) { fichier << p_v->modele << endl ; // A->B : (*A).B } } void afficher(ostream& fichier, vector const& L) { for (auto p_p : L) fichier << " - " << p_p->nom << endl; } void afficher(ostream& fichier, Personne const& p) { fichier << p.nom << " a pour amis :" << endl; afficher(fichier, p.amis); // afficher(fichier, p.g); } string demander() { cout << "Entrez un nom de fichier : "; string nom; cin >> nom; // getline est mieux return nom; } void ouvrir(ofstream& f, string const& nom) { f.open(nom); if (f.fail()) throw 42; } int main() { Personne c({ "C", {} }); Personne a({ "A", { &c } }); ofstream sortie; string nom_fichier; try { ouvrir(sortie, nom_fichier = demander()); } catch (int) { cerr << "pas réussi à ouvrir " << nom_fichier << endl;; return 1; } afficher(sortie, a); return 0; }