- //Cette classe est une table associant
- //une clee a une valeur : une sorte de
- //tableau sauf que les indices ne sont
- //plus un entier, mais une chaine de
- //caractere, ou autre ...
-
- #include <stdio.h>
- #include <map>
- #include <string>
-
- int main(int argc, char ** argv){
-
- //on declare un tableau d'entier qui sera indexe par une chaine
- std::map<std::string, int> mapAgenda;
-
- //on ajoute quelques valeurs
- mapAgenda["toto"] = 12;
- mapAgenda["titi"] = 1000330055;
-
- //on declare un iterateur sur cette map
- std::map<std::string, int>::iterator iter;
-
- //on cherche la chaine tibur
- iter = mapAgenda.find( "tibur" );
-
- if (iter==mapAgenda.end()){ //on a pas trouve
- printf("tibur non trouve\n");
- }
- else{
- printf("hum\n");
- }
-
- //on cherche toto
- iter = mapAgenda.find( "toto" );
-
- if (iter==mapAgenda.end()){ //on a pas trouve
- printf("toto non trouve\n");
- }
- else{ //on a trouve
- int num = mapAgenda["toto"]; //on recupere l'entier depuis notre map
- // int num = iter->second;
- printf("toto trouve : num = %d\n", num); //on l'affiche
- }
-
-
-
- return 0;
- }
- //neiger@ifrance.com
//Cette classe est une table associant
//une clee a une valeur : une sorte de
//tableau sauf que les indices ne sont
//plus un entier, mais une chaine de
//caractere, ou autre ...
#include <stdio.h>
#include <map>
#include <string>
int main(int argc, char ** argv){
//on declare un tableau d'entier qui sera indexe par une chaine
std::map<std::string, int> mapAgenda;
//on ajoute quelques valeurs
mapAgenda["toto"] = 12;
mapAgenda["titi"] = 1000330055;
//on declare un iterateur sur cette map
std::map<std::string, int>::iterator iter;
//on cherche la chaine tibur
iter = mapAgenda.find( "tibur" );
if (iter==mapAgenda.end()){ //on a pas trouve
printf("tibur non trouve\n");
}
else{
printf("hum\n");
}
//on cherche toto
iter = mapAgenda.find( "toto" );
if (iter==mapAgenda.end()){ //on a pas trouve
printf("toto non trouve\n");
}
else{ //on a trouve
int num = mapAgenda["toto"]; //on recupere l'entier depuis notre map
// int num = iter->second;
printf("toto trouve : num = %d\n", num); //on l'affiche
}
return 0;
}
//neiger@ifrance.com