Bonjour j'ai un petit souçi avec l'affichage d'un char*, voilà mon code
Etudiant.hpp
Etudiant.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 class Etudiant { public: Etudiant(const char* nom); ~Etudiant(); friend ostream& operator<<(std::ostream& o,const Etudiant&); private: int id; char* nom; };
main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Etudiant::Etudiant(const char* lenom) { if(lenom) { this->nom=new char[strlen(lenom)+1]; strcpy(nom,lenom); } } std::ostream& operator<<(std::ostream& o,const Etudiant& s) { o << "Nom :"<<s.nom<< endl; return o; }
ça compile sans aucun problème, mais à l’exécution il m'affiche l'adresse mémoire de e1 mais pas le nom, moi je veux afficher que le nom
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 int main() { Etudiant *e1= new Etudiant("toto"); cout << e1 << endl; return 0; }
voilà, si quelqu'un a une idée
Partager