Afficher une chaîne de caractère
Bonjour j'ai un petit souçi avec l'affichage d'un char*, voilà mon code
Etudiant.hpp
Code:
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;
}; |
Etudiant.cpp
Code:
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;
} |
main.cpp
Code:
1 2 3 4 5 6 7 8
|
int main()
{
Etudiant *e1= new Etudiant("toto");
cout << e1 << endl;
return 0;
} |
ç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
voilà, si quelqu'un a une idée