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 :

erreur sur #include <vector>


Sujet :

C++

  1. #1
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut erreur sur #include <vector>
    voici ce que donne #include <vector>

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    #include <string>
    #include <vector>
     
    #include "recursgauche.hpp"
    ...
    Code : 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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    $ g++ recursgauche.cpp
    In file included from /usr/include/c++/10/vector:66,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _ForwardIterator = std::vector<std::__cxx11::basic_string<char> >*]’:
    /usr/include/c++/10/bits/stl_uninitialized.h:325:37:   required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _ForwardIterator = std::vector<std::__cxx11::basic_string<char> >*; _Tp = std::vector<std::__cxx11::basic_string<char> >]’
    /usr/include/c++/10/bits/vector.tcc:751:34:   required from ‘void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1665:19:   required from ‘void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1383:22:   required from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; <template-parameter-2-2> = void; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::const_iterator]’
    recursgauche.cpp:37:33:   required from here
    /usr/include/c++/10/bits/stl_uninitialized.h:137:72: error: static assertion failed: result type must be constructible from value type of input range
      137 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
          |                                                                  ^~~~~
     
    In file included from /usr/include/c++/10/bits/char_traits.h:39,
                     from /usr/include/c++/10/string:40,
                     from recursgauche.cpp:1:
    /usr/include/c++/10/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’:
    /usr/include/c++/10/bits/stl_algobase.h:472:30:   required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’
    /usr/include/c++/10/bits/stl_algobase.h:506:42:   required from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’
    /usr/include/c++/10/bits/stl_algobase.h:514:31:   required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _OI = __gnu_cxx::__normal_iterator<std::vector<std::__cxx11::basic_string<char> >*, std::vector<std::vector<std::__cxx11::basic_string<char> > > >]’
    /usr/include/c++/10/bits/stl_algobase.h:569:7:   required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _OI = __gnu_cxx::__normal_iterator<std::vector<std::__cxx11::basic_string<char> >*, std::vector<std::vector<std::__cxx11::basic_string<char> > > >]’
    /usr/include/c++/10/bits/vector.tcc:744:16:   required from ‘void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1665:19:   required from ‘void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1383:22:   required from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; <template-parameter-2-2> = void; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::const_iterator]’
    recursgauche.cpp:37:33:   required from here
    /usr/include/c++/10/bits/stl_algobase.h:380:18: error: no match foroperator=’ (operand types are ‘std::vector<std::__cxx11::basic_string<char> >’ and ‘std::__cxx11::basic_string<char>’)
      380 |        *__result = *__first;
          |        ~~~~~~~~~~^~~~~~~~~~
    In file included from /usr/include/c++/10/vector:72,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]198 |     vector<_Tp, _Alloc>::
          |     ^~~~~~~~~~~~~~~~~~~
    /usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘const std::vector<std::__cxx11::basic_string<char> >&’
      199 |     operator=(const vector<_Tp, _Alloc>& __x)
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
    In file included from /usr/include/c++/10/vector:67,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
          |       ^~~~~~~~
    /usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘std::vector<std::__cxx11::basic_string<char> >&&’
      709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
          |                 ~~~~~~~~~^~~
    /usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]730 |       operator=(initializer_list<value_type> __l)
          |       ^~~~~~~~
    /usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘std::initializer_list<std::__cxx11::basic_string<char> >’
      730 |       operator=(initializer_list<value_type> __l)
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
    quelqu'un a une idée?

  2. #2
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut
    Code : 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
    31
    32
    33
    34
    35
    36
    37
    38
    #include <string>
    #include <vector>
     
    #include "recursgauche.hpp"
     
    void traiement_grammaire::traitement(){
      for(size_t i=0;i<liste_productions.size();i++){
        std::vector<std::string>production_courante=liste_productions[i];
        bool modif=false;
        do{
          std::vector<std::string>corps_courant=production_courante;
          corps_courant.erase(corps_courant.begin());//on enlève la tête
          for(int j=0;j<i;j++){
    	//production_precedente est une production précédente
    	std::string production_precedente = liste_productions[j][0];
    	if(corps_courant[0]==production_precedente){//si la production commence par un
    	  //nonterminal précédent
    	  std::vector<std::string>reste_production=corps_courant;
    	  reste_production.erase(reste_production.begin());//on enlève le terminal trouvé
    	  //on supprime la production
    	  liste_productions.erase(liste_productions.begin()+i);
              modif=true;
    	  for(int k=0;k<i;k++){
    	    if(liste_productions[k][0]==production_precedente){
    	      std::vector<std::string>nouvelle_production;
    	      nouvelle_production.push_back(production_courante[0]);
    	      std::vector<std::string> corps_precedent = liste_productions[k];
    	      corps_precedent.erase(corps_precedent.begin());
    	      corps_precedent.insert(corps_precedent.end(),reste_production.begin(),reste_production.end());
    	      nouvelle_production.insert(nouvelle_production.end(),corps_precedent.begin(),corps_precedent.end());
    	      liste_productions.insert(liste_productions.begin()+i,nouvelle_production.begin(),nouvelle_production.end());
    	    }
    	  }
    	}
          }
        }while(modif);
      }
    }
    Code : 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
    #ifndef RECURSGAUCHE_HPP
    #define RECURSGAUCHE_HPP
    #include <string>
    #include <vector>
     
    class traiement_grammaire{
    public:
      void traitement();
    private:
      std::vector<std::vector<std::string>>liste_productions={
        { "A","B","C" }, //A -> B C
        { "B","D","E"},  //B -> D E
        { "B","F","G"},  //B -> F G
        { "D","A","H"}  //D -> A H recursivité à gauche indirecte
      };
    };
    #endif

  3. #3
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2018
    Messages
    104
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2018
    Messages : 104
    Par défaut
    Ce sera quand même rarement la faute de la librairie standard

    Quand je tombe sur ce genre de longue erreur, la 1ère chose que je fais, c'est Ctrl+F ".cpp" dans l'erreur.
    Ici, je trouve des recursgauche.cpp:2 qui correspondent à l'include du vector, on peut ignorer. On trouve aussi des recursgauche.cpp:37 qui nous intéressent plus.
    Par contre, ligne 37, je ne vois rien. Donc j'imagine que tu n'as pas mis tout le code ? Qu'est-ce qui s'y trouve réellement ?

    En tout cas, en survolant l'erreur rapidement, j'ai l'impression que tu essaies d'affecter un std::string à un std::vector<std::string> (par une affectation directe ou ça pourrait être un push_back d'un std::string dans un std::vector<std::vector<std::string>> par exemple, ou encore autre chose...)

  4. #4
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut
    Merci d'avoir répondu

    j'ai modifié le programme comme ceci:
    Code : 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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    #include <string>
    #include <vector>
     
    #include "recursgauche.hpp"
     
    void traiement_grammaire::traitement(){
      for(size_t i=0;i<liste_productions.size();i++){
        std::vector<std::string>production_courante;
        production_courante=liste_productions[i];
        bool modif=false;
        do{
          std::vector<std::string>corps_courant;
          corps_courant=production_courante;
          corps_courant.erase(corps_courant.begin());//on enlève la tête
          for(int j=0;j<i;j++){
    	//production_precedente est une tete d'une production précédente
    	std::string production_precedente;
     	production_precedente = liste_productions[j][0];
    	if(corps_courant[0]==production_precedente){//si la production commence par un nonterminal précédent
    	  std::vector<std::string>reste_production;
    	  reste_production=corps_courant;
    	  reste_production.erase(reste_production.begin());//on enlève le terminal trouvé
    	  //on supprime la production
    	  liste_productions.erase(liste_productions.begin()+i);
    	  modif=true;
    	  for(size_t k=0;k<liste_productions.size();k++){
    	    if(liste_productions[k][0]==production_precedente){
    	      std::vector<std::string>nouvelle_production;
    	      nouvelle_production.push_back(production_courante[0]);
    	      std::vector<std::string> corps_precedent;
    	      corps_precedent = liste_productions[k];
    	      corps_precedent.erase(corps_precedent.begin());
    	      std::vector<std::string>::iterator it=corps_precedent.end();
    	      corps_precedent.insert(it,reste_production.begin(),reste_production.end());
    	      it=nouvelle_production.end();
    	      nouvelle_production.insert(it,corps_precedent.begin(),corps_precedent.end());
    	      std::vector<std::vector<std::string>>::iterator it2;
    	      it2=liste_productions.begin()+i;
    	      liste_productions.insert(it2,nouvelle_production.begin(),nouvelle_production.end());
    	    }
    	  }
    	}
          }
        }while(modif);
      }
    }
    Code : 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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    $ g++ -c recursgauche.cpp
    In file included from /usr/include/c++/10/vector:66,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _ForwardIterator = std::vector<std::__cxx11::basic_string<char> >*]’:
    /usr/include/c++/10/bits/stl_uninitialized.h:325:37:   required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _ForwardIterator = std::vector<std::__cxx11::basic_string<char> >*; _Tp = std::vector<std::__cxx11::basic_string<char> >]’
    /usr/include/c++/10/bits/vector.tcc:751:34:   required from ‘void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1665:19:   required from ‘void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1383:22:   required from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; <template-parameter-2-2> = void; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::const_iterator]’
    recursgauche.cpp:39:90:   required from here
    /usr/include/c++/10/bits/stl_uninitialized.h:137:72: error: static assertion failed: result type must be constructible from value type of input range
      137 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
          |                                                                  ^~~~~
     
    In file included from /usr/include/c++/10/bits/char_traits.h:39,
                     from /usr/include/c++/10/string:40,
                     from recursgauche.cpp:1:
    /usr/include/c++/10/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’:
    /usr/include/c++/10/bits/stl_algobase.h:472:30:   required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’
    /usr/include/c++/10/bits/stl_algobase.h:506:42:   required from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = std::__cxx11::basic_string<char>*; _OI = std::vector<std::__cxx11::basic_string<char> >*]’
    /usr/include/c++/10/bits/stl_algobase.h:514:31:   required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _OI = __gnu_cxx::__normal_iterator<std::vector<std::__cxx11::basic_string<char> >*, std::vector<std::vector<std::__cxx11::basic_string<char> > > >]’
    /usr/include/c++/10/bits/stl_algobase.h:569:7:   required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _OI = __gnu_cxx::__normal_iterator<std::vector<std::__cxx11::basic_string<char> >*, std::vector<std::vector<std::__cxx11::basic_string<char> > > >]’
    /usr/include/c++/10/bits/vector.tcc:744:16:   required from ‘void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1665:19:   required from ‘void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator]’
    /usr/include/c++/10/bits/stl_vector.h:1383:22:   required from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; <template-parameter-2-2> = void; _Tp = std::vector<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::vector<std::__cxx11::basic_string<char> > >; std::vector<_Tp, _Alloc>::iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<std::vector<std::__cxx11::basic_string<char> > >::const_iterator]’
    recursgauche.cpp:39:90:   required from here
    /usr/include/c++/10/bits/stl_algobase.h:380:18: error: no match foroperator=’ (operand types are ‘std::vector<std::__cxx11::basic_string<char> >’ and ‘std::__cxx11::basic_string<char>’)
      380 |        *__result = *__first;
          |        ~~~~~~~~~~^~~~~~~~~~
    In file included from /usr/include/c++/10/vector:72,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]198 |     vector<_Tp, _Alloc>::
          |     ^~~~~~~~~~~~~~~~~~~
    /usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘const std::vector<std::__cxx11::basic_string<char> >&’
      199 |     operator=(const vector<_Tp, _Alloc>& __x)
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
    In file included from /usr/include/c++/10/vector:67,
                     from recursgauche.cpp:2:
    /usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
          |       ^~~~~~~~
    /usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘std::vector<std::__cxx11::basic_string<char> >&&’
      709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
          |                 ~~~~~~~~~^~~
    /usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >]730 |       operator=(initializer_list<value_type> __l)
          |       ^~~~~~~~
    /usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘std::initializer_list<std::__cxx11::basic_string<char> >’
      730 |       operator=(initializer_list<value_type> __l)
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

  5. #5
    Membre éclairé

    Homme Profil pro
    développeur à la maison
    Inscrit en
    Septembre 2006
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn et Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : développeur à la maison

    Informations forums :
    Inscription : Septembre 2006
    Messages : 393
    Billets dans le blog
    16
    Par défaut
    ça y est ça marche:
    Code : 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
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    #include <string>
    #include <vector>
     
    #include "recursgauche.hpp"
     
    void traiement_grammaire::traitement(){
      for(size_t i=0;i<liste_productions.size();i++){
        std::vector<std::string>production_courante;
        production_courante=liste_productions[i];
        bool modif=false;
        do{
          std::vector<std::string>corps_courant;
          corps_courant=production_courante;
          corps_courant.erase(corps_courant.begin());//on enlève la tête
          for(int j=0;j<i;j++){
    	//production_precedente est une tete d'une production précédente
    	std::string production_precedente;
     	production_precedente = liste_productions[j][0];
    	if(corps_courant[0]==production_precedente){//si la production commence par un nonterminal précédent
    	  std::vector<std::string>reste_production;
    	  reste_production=corps_courant;
    	  reste_production.erase(reste_production.begin());//on enlève le terminal trouvé
    	  //on supprime la production
    	  liste_productions.erase(liste_productions.begin()+i);
    	  modif=true;
    	  for(size_t k=0;k<liste_productions.size();k++){
    	    if(liste_productions[k][0]==production_precedente){
    	      std::vector<std::string>nouvelle_production;
    	      nouvelle_production.push_back(production_courante[0]);
    	      std::vector<std::string> corps_precedent;
    	      corps_precedent = liste_productions[k];
    	      corps_precedent.erase(corps_precedent.begin());
    	      std::vector<std::string>::iterator it=corps_precedent.end();
    	      corps_precedent.insert(it,reste_production.begin(),reste_production.end());
    	      it=nouvelle_production.end();
    	      nouvelle_production.insert(it,corps_precedent.begin(),corps_precedent.end());
    	      std::vector<std::vector<std::string>>::iterator it2;
    	      std::vector<std::vector<std::string>>nouvelle_liste;
    	      it2=liste_productions.begin()+i;
    	      nouvelle_liste.push_back(nouvelle_production);
    	      liste_productions.insert(it2,nouvelle_liste.begin(),nouvelle_liste.end());
    	    }
    	  }
    	}
          }
        }while(modif);
      }
    }

  6. #6
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2018
    Messages
    104
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2018
    Messages : 104
    Par défaut
    Effectivement, je vois que tu as réglé ton problème dans ton dernier code en considérant que le std::vector::insert ajoute forcément les éléments d'une liste. Et donc tu as créé une liste contenant l'unique élément que tu veux rajouter, pour ensuite rajouter cette liste (ligne 41 de ton dernier code).
    Tu devrais jeter un coup d'oeil à la doc : https://cplusplus.com/reference/vector/vector/insert/
    Le insert permet bien de rajouter une liste grâce à la signature (3) de la doc. Mais en fait, tu peux ajouter un unique élément avec la signature (1), donc faire simplement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    liste_productions.insert(it2, nouvelle_production);
    Voire encore mieux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    liste_productions.insert(it2, std::move(nouvelle_production));
    pour éviter de copier nouvelle_production. Mais tu devras certainement te renseigner sur les c++ move semantics.
    Vu que tu as l'air d'utiliser beaucoup de std::vector et std::string, si tu as besoin de gagner en performance, cette notion sera très importante.

  7. #7
    Membre éclairé
    Homme Profil pro
    Ingénieur validation
    Inscrit en
    Août 2018
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur validation
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2018
    Messages : 41
    Par défaut
    Bonjour

    Quand je vois autant de erase et de insert dans un tel code, je me demande si std::vector est le conteneur adapté.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/10/2014, 21h55
  2. Erreur sur un include
    Par yurispy dans le forum Langage
    Réponses: 3
    Dernier message: 02/06/2014, 19h45
  3. erreur sur fichier /usr/include/iso/stdlib_iso.h
    Par gronaze dans le forum Unix
    Réponses: 1
    Dernier message: 21/07/2009, 17h24
  4. erreur sur Include
    Par dsr57 dans le forum Administration
    Réponses: 2
    Dernier message: 26/08/2008, 08h36
  5. erreur sur l'include de <afxwin.h> ?
    Par ebureau dans le forum C++/CLI
    Réponses: 8
    Dernier message: 07/08/2008, 15h31

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