IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Problème d'affichage d'une multimap


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mars 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2008
    Messages : 39
    Par défaut Problème d'affichage d'une multimap
    bonjour,

    Voici mon problème :
    j'ai une multimap std::multimap<int, std::map<std::string, std::string> >

    j'ai crée un itérateur sur cette multimap et j'ai fait une boucle pour afficher son contenu :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    for(it = laMapCalendrier.begin() ; it != laMapCalendrier.end() ; it++)
        {
            std::cout << it->first << "|";
            std::cout << it->second.first << "|";
            std::cout << it->second.second<<std::endl;
        }
    mais le compilateur me met une erreur pour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::cout << it->second.first << "|";
    et je ne sais pas comment faire pour que ça marche

    Merci d'avance pour votre aide

  2. #2
    Membre Expert

    Profil pro
    Inscrit en
    Juin 2006
    Messages
    1 294
    Détails du profil
    Informations personnelles :
    Localisation : Royaume-Uni

    Informations forums :
    Inscription : Juin 2006
    Messages : 1 294
    Par défaut
    Salut,

    it->second est de type std::map<std::string, std::string> et n'a donc pas de membre first.
    Tu vas devoir faire une 2e boucle imbriquée...

    MAT.

  3. #3
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mars 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2008
    Messages : 39
    Par défaut
    J'ai essayé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
        for(it = laMapCalendrier.begin() ; it != laMapCalendrier.end() ; it++)
        {
            std::cout << it->first;
            for(it3 = mapMatch.begin(); it3 != mapMatch.end(); it3++)
            {
                std::cout << it3->first << "," << it3->second;
            }
        }
    avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::multimap<int, std::map<std::string, std::string> > laMapCalendrier;
    std::map<std::string, std::string> mapMatch;
    std::multimap<int, std::map<std::string, std::string> >::const_iterator it;
    std::map<std::string, std::string>::const_iterator it3;
    mais quand j'essaye de compiler, le fichier stl_pair.h s'ouvre pour me dire qu'il y a une erreur dans ce fichier

  4. #4
    Membre Expert

    Profil pro
    Inscrit en
    Juin 2006
    Messages
    1 294
    Détails du profil
    Informations personnelles :
    Localisation : Royaume-Uni

    Informations forums :
    Inscription : Juin 2006
    Messages : 1 294
    Par défaut
    Peux-tu prendre la bonne habitude de donner un code minimal qui reproduit le problème, le but étant qu'on ait juste à le copier-coller dans un fichier pour pouvoir le compiler ?
    Et puis donne aussi un copier-coller de la sortie du compilateur pour avoir les erreurs exactes (ou au moins la première), en indiquant à quelle ligne précise ça correspond dans le code que tu donnes.
    Parce que "mais quand j'essaye de compiler, le fichier stl_pair.h s'ouvre pour me dire qu'il y a une erreur dans ce fichier", c'est à la fois vague et pas très réaliste...

    Sinon en général on écrit ++it et non it++ dans une boucle.

    MAT.

  5. #5
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mars 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2008
    Messages : 39
    Par défaut
    ok je donnerais ce qui est nécessaire demain

    pour le it++, j'ai toujours appris comme ça, mais c'est bon à savoir, j'essaierai de faire gaffe dorénavant

  6. #6
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Mars 2008
    Messages
    39
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2008
    Messages : 39
    Par défaut
    Code Mon hpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    #include "Equipe.hpp"
    #include <vector>
    #include <string>
     
    class Championnat
    {
        std::vector <std::string> lesEquipes;
        public:
        void statistique();
        void genererCalendrier();
    };

    Code Le cpp (sachant que je remplis mon vector avant) : 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
        std::vector<std::string>::const_iterator it1, it2;
        std::multimap<int, std::map<std::string, std::string> > laMapCalendrier;
        std::map<std::string, std::string> mapMatch;
     
        int leNumeroJournee=1;
        for(it1 = lesEquipes.begin() ; it1 != lesEquipes.end() ; it1++)
        {
            it2=it1;
            for( it2++ ; it2 != lesEquipes.end() ; it2++)
            {
                std::pair<std::string, std::string> p(*it1, *it2);
                leNumeroJournee=(leNumeroJournee+1)%(sonNombreEquipe-1)+1;
                std::pair<int, std::pair<std::string, std::string> >p2(leNumeroJournee, p);
                laMapCalendrier.insert(p2);
     
            }
        }
     
        int leNombreJourneeAller = sonNombreEquipe-1;
        std::multimap<int, std::map<std::string, std::string> >::const_iterator it;
        std::map<std::string, std::string>::const_iterator it3;
        std::cout<<"Matchs Aller"<<std::endl;
        for(it = laMapCalendrier.begin() ; it != laMapCalendrier.end() ; it++)
        {
            std::cout << it->first;
            for(it3 = mapMatch.begin(); it3 != mapMatch.end(); it3++)
            {
                std::cout << it3->first << "," << it3->second;
            }
        }

    Code Les erreurs : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ||=== gestion_championnat, Debug ===|
    E:\IUT\projet_prog2\gestion_championnat\championnat.cpp||In member function `void Championnat::genererCalendrier()':|
    E:\IUT\projet_prog2\gestion_championnat\championnat.cpp|84|warning: unused variable 'leNombreJourneeAller'|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_pair.h||In constructor `std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = int, _U2 = std::pair<std::string, std::string>, _T1 = const int, _T2 = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >]':|
    E:\IUT\projet_prog2\gestion_championnat\championnat.cpp|79|instantiated from here|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_pair.h|90|error: no matching function for call to `std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >::map(const std::pair<std::string, std::string>&)'|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_map.h|166|note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_map.h|156|note:                 std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::allocator_type&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_map.h|148|note:                 std::map<_Key, _Tp, _Compare, _Alloc>::map() [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]|
    ||=== Build finished: 1 errors, 1 warnings ===|

Discussions similaires

  1. [C#] problème d'affichage d'une nouvelle Form
    Par michel_frederic dans le forum C#
    Réponses: 15
    Dernier message: 17/11/2005, 16h40
  2. Problème avec affichage d'une table modifiée
    Par auriolbeach dans le forum Access
    Réponses: 6
    Dernier message: 31/10/2005, 15h45
  3. [GD] Problème d'affichage d'une image avec gd2
    Par turini dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 04/10/2005, 11h59
  4. Problème d'affichage d'une chaîne à l'écran
    Par Bubonik software dans le forum C
    Réponses: 7
    Dernier message: 08/05/2004, 20h47
  5. probléme d'affichage d'une fiche
    Par sb dans le forum Composants VCL
    Réponses: 7
    Dernier message: 29/08/2002, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo