Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1865 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  map<string, vector<string>> find

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

map<string, vector<string>> find

n°2177822
jetaimerog​er
Posté le 27-02-2013 à 17:19:53  profilanswer
 

Salut
 
Comment utiliser find?

Citation :


vector<string> listValue;
 map<string, vector<string>> mapValue;
 
            iterMapValue = mapValue.find("base1" );
      for (iterMapValue = mapValue.begin(); iterMapValue != mapValue.end(); iterMapValue++) {
   cout <<  iterMapValue->first << "iterMapValue->first" << endl;
      }


resultat il me parcourt toute la map et moi je veux que "base1"?

mood
Publicité
Posté le 27-02-2013 à 17:19:53  profilanswer
 

n°2177823
jetaimerog​er
Posté le 27-02-2013 à 17:24:51  profilanswer
 

j'ai trouvé cout << "mapValue:  " << iterMapValue->first << endl;

n°2177828
theshockwa​ve
I work at a firm named Koslow
Posté le 27-02-2013 à 17:45:38  profilanswer
 

attention à la portée de tes variables (ton iterateur devrait sans doute être déclaré à l'intérieur de ta boucle for) et à l'opérateur d'incrémentation que tu utilises (toujours préférer le préfixé au postfixé)
 
Au delà de ca, oui, déréférencer un itérateur sur une map retourne une référence vers une std::pair dont first contient la clé et second contient la donnée associée.


---------------
last.fm
n°2177830
Farian
Posté le 27-02-2013 à 17:48:54  profilanswer
 

Bonjour !
 
Si vous récupérez un itérateur via un "find", vous devez d'abord tester qu'il est valide (différent de map.end()) avant d'en afficher la valeur (en l'occurrence, vous affichez la clé, un itérateur étant un pointeur sur une std::pair, la valeur est dans iter->second).
 
Bonne continuation !

n°2177834
theshockwa​ve
I work at a firm named Koslow
Posté le 27-02-2013 à 17:58:49  profilanswer
 

Farian a écrit :

un itérateur étant un pointeur sur une std::pair


 
Ca ressemble à un pointeur, mais ce n'est pas un pointeur.
 


---------------
last.fm

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  map<string, vector<string>> find

 

Sujets relatifs
[c++][encodage UTF-16] longueur d'une stringfonction find
Automatisation de "remplacement" String texte - code[VBA] Fonction find avec plusieurs criteres
[C] Conversion type énuméré en string pour affichage :asynchronous task avec connection string d'une application fille
std::find dans un setfind > exclure motifs fichiers & repertoires
[C] retourner un tableau de stringtinyMCE => PHP => MySQL : erreur UTF-8 (Incorrect string value)
Plus de sujets relatifs à : map<string, vector<string>> find


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR