A voir également:
- Programmation en langage c++
- Langage ascii - Guide
- Application de programmation - Guide
- Langage binaire - Guide
- Pascal langage - Télécharger - Édition & Programmation
- Mettre en veille un programme - Guide
5 réponses
Comme ça, je dirai que comme tu enregistre dans ton tableau le pointeur vers un objet"string" et ce cette objet est réutilisé, en gros, tu ne fais qu'ajouter le même objet et donc ça ne conserve que la dernière saisie.
oui désoler c'est vrai, voila donc mon code est ne tenais pas compte des noms des dossiers.
///////////////////////////////pointeur.cpp//////////////////////////////// #include<iostream> #include<string> #include"pointeur.hpp" using namespace std; char encore; int c=0; string tab[5][5]; int main(){ pointeur p; string b; string *a{new string()}; a=&b; do { p.remplir(tab); cout<<"ecrivez un mot"<<endl; cin>>b; tab[c][0]=*a; c=c+1; if (c==5) { p.affiche(tab); return 0; } else { } p.affiche(tab); cout<<"encore un mot?"<<endl; cin>>encore; } while (encore=='o'); p.affiche(tab); return 0; } ///////////////////////////////pointeur.hpp//////////////////////////////// #include <iostream> #include <string> using namespace std; class pointeur { private: /* data */ public: pointeur(); void affiche(string tab[5][5]); void remplir(string tab[5][5]); }; pointeur::pointeur() { } void pointeur::affiche(string tab[5][5]){ system("clear"); for (int i = 0; i < 5; i++){ for(int j = 0; j < 5; j++){ cout<< tab[i][j]<<' '; } cout<< endl ; } } void pointeur::remplir(string tab[5][5]){ for (int i=0 ; i<5 ;i++){ for (int j=0 ; j<5 ; j++){ tab[i][j]=' '; } } }
Et il n'y a toujours pas les balise de code:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include<iostream> #include<string> #include"pointeur.hpp" using namespace std; char encore; int c=0; string tab[5][5]; int main(){ pointeur p; string b; string *a{new string()}; a=&b; do { p.remplir(tab); cout<<"ecrivez un mot"<<endl; cin>>b; tab[c][0]=*a; c=c+1; if (c==5) { p.affiche(tab); return 0; } else { } p.affiche(tab); cout<<"encore un mot?"<<endl; cin>>encore; } while (encore=='o'); p.affiche(tab); return 0; }
///////////////////////////////pointeur.hpp////////////////////////////////
#include <iostream> #include <string> using namespace std; class pointeur { private: /* data */ public: pointeur(); void affiche(string tab[5][5]); void remplir(string tab[5][5]); }; pointeur::pointeur() { } void pointeur::affiche(string tab[5][5]){ system("clear"); for (int i = 0; i < 5; i++){ for(int j = 0; j < 5; j++){ cout<< tab[i][j]<<' '; } cout<< endl ; } } void pointeur::remplir(string tab[5][5]){ for (int i=0 ; i<5 ;i++){ for (int j=0 ; j<5 ; j++){ tab[i][j]=' '; } } }