Bonjour, Je veux convertir un int en string mais en utilisant stringstream mais le code ne marche pas
et mon 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
18
19
20
21
22
23
24
25
26
27
28
29
30
31 /* * Exercice19.h * * Created on: Jan 15, 2011 * Author: hibou */ #ifndef EXERCICE19_H_ #define EXERCICE19_H_ #include<iostream> #include<string> #include <string.h> using namespace std; enum SEX {HOMME,FEMME}; class Personne{ public: Personne(); Personne(string, string, int, SEX); string Affiche() const; private: string nom; string prenom; int age; SEX sex; }; #endif /* EXERCICE19_H_ */
L'erreur est dans la méthode Affiche en fait
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 /* * Exercice19.cpp * * Created on: Jan 15, 2011 * Author: hibou */ #include <iostream> #include <string> #include "Exercice19.h" using namespace std; Personne::Personne(){ } Personne::Personne(string nom1, string prenom1, int age1, SEX sex1){ nom=nom1; prenom=prenom1; age=age1; sex=sex1; } string Personne::Affiche() const{ stringstream out; out<<age; return out<<age; // "nom:"+nom + "\n"+ // "prenom:"+prenom+"\n"+ // "age:"+age+"\n"; } int main(){ Personne p("nam","hibou",25,HOMME); string s; s=p.Affiche(); cout<<s; return 0; }
Partager