chepa_jemls | je m'explique: (si vous comprenez pas, dites le moi, je m'expliquerai)
j'ai un vecteur dans un multiset, j'écris le multiset dans un fichier!! après je veux relire!! tout va bien sauf qu'il ne s'arrêt pas!!
Pourtant avant, j'écivais seulment le nom et prénom dans le fichier et cela marchait!! j'ai donc mis un délimiteur marquent la fin du vecteur (c'est le mot bidon)!!
mais a chaque foi qu'il arrive à la fin du fichier, il veut relire un élément suplémentaire!! mais qui est vide bien entendu!!!! alors il boucle car il trouve pas le mot bidon!!!
help!!
déclaration des fonctions
Code :
- #include <iostream>
- #include <set>
- #include <string>
- #include <iterator>
- #include <fstream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- class personne
- {
- private:
- string nom;
- string prenom;
- vector<string> tab;
- public:
- personne();
- personne(string,string);
- ~personne();
- string getNom() const;
- string getPrenom()const;
- void setnomprenom(string, string,vector<string> );
- friend ostream& operator<<(ostream&, const personne& );
- friend istream& operator>>(istream&, personne& );
- };
- void systempause();
- void systemcls();
- //Foncteur qui cree une fonction pour le tri
- struct tri{
- bool operator()(const personne &a,const personne &b) const
- {
- if (a.getNom() == b.getNom())
- return ( a.getPrenom() < b.getPrenom()) ;
- else
- return ( a.getNom() < b.getNom()) ;
- };
- };
|
définiton des fonctions
Code :
- #include "header.h"
- /****************************************************************
- *Fonction: systecls *
- *****************************************************************
- *Description: *
- * Efface l ecran *
- ****************************************************************/
- void systemcls(){
- //system("clear" );
- system("cls" );
- };
- /****************************************************************
- *Fonction: systempause *
- *****************************************************************
- *Description: *
- * Fait une pause *
- ****************************************************************/
- void systempause(){
- //char touche;
- //printf("Appuyez sur la touche enter pour continuer..." );
- //scanf("\n%c",&touche);
- system("pause" );
- };
- /****************************************************************
- *Fonction: client *
- *****************************************************************
- *Description: *
- * Constructeur par défaut de client *
- ****************************************************************/
- personne::personne():nom(" " ),prenom(" " ){
- };
- /****************************************************************
- *Fonction: getNom *
- *****************************************************************
- *Description: *
- * Renvoi la valeur de nom *
- ****************************************************************/
- string personne::getNom()const{
- return nom;
- };
- /****************************************************************
- *Fonction: getPrenom *
- *****************************************************************
- *Description: *
- * Renvoi la valeur de nom *
- ****************************************************************/
- string personne::getPrenom()const{
- return prenom;
- };
- /****************************************************************
- *Fonction: operator << *
- *****************************************************************
- *Description: *
- * Surcharge de l operateur de flux de sortie *
- ****************************************************************/
- ostream& operator<<(ostream &os,const personne &src){
- cout<<"new personne"<<endl;
- os<<"src.getNom()<<" "<<src.getPrenom()<<" ";
- for(unsigned int cpt=0;cpt<src.tab.size();cpt++){
- os<<src.tab[cpt]<<" ";
- };
- //marque la fin du vecteur
- os<<"bidon"<<endl;
- return os;
- };
- istream& operator>>(istream &os,personne &src){
- string nom1,prenom1,string_temp;
- vector<string> temp;
- int essai=0;
- os>>nom1;
- os>>prenom1;
- os>>string_temp;
- while (essai==0){
- if(string_temp=="bidon" ){
- essai=1;
- cout<<"trouve"<<endl;
- }
- else {
- temp.push_back(string_temp);
- os>>string_temp;
- };
- };
- src.setnomprenom(nom1,prenom1,temp);
- return os;
- };
- /****************************************************************
- *Fonction: ~client *
- *****************************************************************
- *Description: *
- * Constructeur surcharge de client *
- ****************************************************************/
- personne::~personne(){
- };
- /****************************************************************
- *Fonction: setnomprenom *
- *****************************************************************
- *Description: *
- * Permet de creer une personne *
- ****************************************************************/
- void personne::setnomprenom(string a, string b,vector<string> temp)
- {
- nom = a;
- prenom = b;
- this->tab = temp;
- };
|
[#ff0e00]main[/#ff0e00
Code :
- #include "header.h"
- int main(void)
- {
- char choix='1';
- string nom_buffer,prenom_buffer;
- multiset < personne , tri > bd;
- vector<string> temp1;
- personne temp;
- multiset < personne , tri >::iterator it;
- char nom_fichier[50],nom_fichier1[50];
- ofstream fic;
- ifstream fic1;
- //Dans qu on a pas mis quitter
- do
- {
- systemcls();
- cout<<"1 =>Ajout d une personne"<<endl;
- cout<<"2 =>Supprimer une personne"<<endl;
- cout<<"3 =>Liste croissante"<<endl;
- cout<<"4 =>Liste decroissante"<<endl<<endl<<endl;
- cout<<"Q =>Pour quitte le prog"<<endl;
- cout<<"Entrez votre choix: ";
- cin>>choix;
- switch (choix)
- {
- //Ajout d une personne
- case '1':
- cout<<"Entrez le nom: ";
- cin>>nom_buffer;
- cout<<"Entrez le prenom :";
- cin>>prenom_buffer;
- temp1.push_back("essai" );
- temp1.push_back("reessai" );
- temp1.push_back("rereessai" );
- temp.setnomprenom(nom_buffer,prenom_buffer,temp1);
- bd.insert(temp);
- systempause();
- break;
- //Suppression d une personne
- /*case '2':
- cout<<endl<<endl<<"Suppression d une personne"<<endl;
- cout<<"**************************"<<endl;
- cout<<"Entrez le nom: ";
- cin>>nom_buffer;
- cout<<"Entrez le prenom :";
- cin>>prenom_buffer;
- temp.setnomprenom(nom_buffer,prenom_buffer);
- if (!bd.erase(temp)) cout<<"-- Valeur non trouvee --";
- systempause();
- break;*/
- //Affichage croissant
- case '3':
- cout<<endl<<endl<<"Liste croissante"<<endl;;
- cout<<"****************"<<endl<<endl;
- copy(bd.begin(),bd.end(),ostream_iterator<personne>(cout,"\n" ));
- systempause();
- break;
- //Affichage decroissant
- case '4':
- cout<<endl<<endl<<"Liste decroissante"<<endl;
- cout<<"******************"<<endl<<endl;
- copy(bd.rbegin(),bd.rend(),ostream_iterator<personne>(cout,"\n" ));
- systempause();
- break;
- case'5':
- cout<<endl<<endl<<"Enregistrement"<<endl;
- cout<<"**************"<<endl<<endl;
- cout<<"Entrez le nom de fichier: "<<endl;
- cin>>nom_fichier;
- fic.open(nom_fichier);
- if (fic!=NULL){
- ostream_iterator<personne>ofi(fic, "" );
- copy(bd.begin(),bd.end(), ofi);
- }else cout<<"--Erreur de création--"<<endl;
- fic.close();
- systempause();
- break;
- case '6':
- cout<<endl<<endl<<"Restauration"<<endl;
- cout<<"************"<<endl<<endl;
- cout<<"Entrez le nom de fichier: "<<endl;
- cin>>nom_fichier1;
- ifstream File(nom_fichier1);
- personne p;
- copy(istream_iterator<personne>(File), istream_iterator<personne>(),inserter(bd, bd.begin()));
- File.close();
- systempause();
- break;
- }
- }while (choix!='q' && choix!='Q');
- return 0;
- }
|
Message édité par chepa_jemls le 11-04-2005 à 15:32:31
|