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

SL & STL C++ Discussion :

error: back_insertor is not a member of std


Sujet :

SL & STL C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert
    Avatar de prgasp77
    Homme Profil pro
    Ingénieur en systèmes embarqués
    Inscrit en
    Juin 2004
    Messages
    1 306
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur en systèmes embarqués
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 306
    Par défaut error: back_insertor is not a member of std
    Bonjour,

    quelqu'un peut-il m'aider à diagnostiquer mon problème ? Sois je commets une grossière erreur de C++ soit j'ai un conflit (voir log de compil'). J'ai compilé et installé sous /opt GCC5.1 ; mon système a GCC4.4 d'installé (/usr/). Ce peut-il que /opt/bin/g++ cherche les includes dans /usr/include ?

    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
    ysc@ysc:/tmp$ cat > test.cpp
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <iterator>
     
    int main(void) {
    	std::string result;
    	std::vector<std::string> vector{"Hello", ",", " ", "World", "!"};
    	std::copy(vector.begin(), vector.end(), std::back_insertor(result));
    	std::cout << result << std::endl;
    	return 0;
    }
    ysc@ysc:/tmp$ /opt/bin/g++ --version
    g++ (GCC) 5.1.0
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     
    ysc@ysc:/tmp$ /opt/bin/g++ -std=c++11 -Wall -Wextra -Werror -O2 -g test.cpp -o test.bin
    test.cpp: In function  int main() :
    test.cpp:9:42: error:  back_insertor  is not a member of  std 
      std::copy(vector.begin(), vector.end(), std::back_insertor(result));
                                              ^
    ysc@ysc:/tmp$
    Merci de votre aide.

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2011
    Messages
    760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

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

    Informations forums :
    Inscription : Juin 2011
    Messages : 760
    Par défaut
    Mmmh, back_inserter ? Pas back_insertor

    J'en profite pour dire que clang propose des noms alternatives quand un identifiant n'existe pas. C'est plutôt pratique pour se type d'erreur.

  3. #3
    Membre Expert
    Avatar de prgasp77
    Homme Profil pro
    Ingénieur en systèmes embarqués
    Inscrit en
    Juin 2004
    Messages
    1 306
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur en systèmes embarqués
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 306
    Par défaut
    Ho la boulette !

    Bon, j'ai tout repris de zero, j'ai même changé de compilo et cette fois j'ai bien l'erreur que j'avais eu au premier abord :
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    $ clang++ -std=c++11 -Wall -Wextra -Werror -O2 -g test.cpp -o test.bin
    In file included from test.cpp:2:
    In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/iostream:39:
    In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ostream:38:
    In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ios:40:
    In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/char_traits.h:39:
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:336:18: error: 
          no viable overloaded '='
                  *__result = *__first;
                  ~~~~~~~~~ ^ ~~~~~~~~
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:396:36: note: 
          in instantiation of function template specialization
          'std::__copy_move<false, false,
          std::random_access_iterator_tag>::__copy_m<std::basic_string<char> *,
          std::back_insert_iterator<std::basic_string<char> > >' requested here
                                  _Category>::__copy_m(__first, __last, __result);
                                              ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:432:23: note: 
          in instantiation of function template specialization
          'std::__copy_move_a<false, std::basic_string<char> *,
          std::back_insert_iterator<std::basic_string<char> > >' requested here
          return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
                          ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:464:20: note: 
          in instantiation of function template specialization
          'std::__copy_move_a2<false,
          __gnu_cxx::__normal_iterator<std::basic_string<char> *,
          std::vector<std::basic_string<char>,
          std::allocator<std::basic_string<char> > > >,
          std::back_insert_iterator<std::basic_string<char> > >' requested here
          return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
                       ^
    test.cpp:11:7: note: in instantiation of function template specialization
          'std::copy<__gnu_cxx::__normal_iterator<std::basic_string<char> *,
          std::vector<std::basic_string<char>,
          std::allocator<std::basic_string<char> > > >,
          std::back_insert_iterator<std::basic_string<char> > >' requested here
            std::copy(vector.begin(), vector.end(), std::back_inserter(result));
                 ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_iterator.h:403:11: note: 
          candidate function (the implicit copy assignment operator) not viable: no
          known conversion from 'std::basic_string<char>' to 'const
          std::back_insert_iterator<std::basic_string<char> >' for 1st argument
        class back_insert_iterator
              ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_iterator.h:403:11: note: 
          candidate function (the implicit move assignment operator) not viable: no
          known conversion from 'std::basic_string<char>' to
          'std::back_insert_iterator<std::basic_string<char> >' for 1st argument
        class back_insert_iterator
              ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_iterator.h:437:7: note: 
          candidate function not viable: no known conversion from
          'std::basic_string<char>' to 'const typename
          basic_string<char>::value_type' (aka 'const char') for 1st argument
          operator=(const typename _Container::value_type& __value)
          ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_iterator.h:444:7: note: 
          candidate function not viable: no known conversion from
          'std::basic_string<char>' to 'typename basic_string<char>::value_type'
          (aka 'char') for 1st argument
          operator=(typename _Container::value_type&& __value)
          ^
    1 error generated.

  4. #4
    Membre Expert
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    1 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 1 711
    Par défaut
    Hello,

    Tu essaies de copier un vecteur de string dans un string (ce qui est plus ou moins un vecteur de char)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    std::copy(vector.begin(), vector.end(), std::back_insertor(result));
     
    // est équivalent à
    result.push_back("Hello"); // un string n'est pas un char
    result.push_back(","); // même problème
    result.push_back(" "); // encore
    result.push_back("World"); // et encore
    result.push_back("!"); // et encore

  5. #5
    Membre Expert
    Avatar de prgasp77
    Homme Profil pro
    Ingénieur en systèmes embarqués
    Inscrit en
    Juin 2004
    Messages
    1 306
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur en systèmes embarqués
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 306
    Par défaut
    Salut,

    j'espérais qu'une spécialisation existait qui utiliserait std::string::append .

  6. #6
    Expert éminent

    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    5 202
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Essonne (Île de France)

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

    Informations forums :
    Inscription : Juin 2007
    Messages : 5 202
    Par défaut
    espérer n'est jamais la bonne idée, il faut se renseigner
    personnellement, j'utilise cppreference.com comme référence

  7. #7
    Membre Expert
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    1 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 1 711
    Par défaut
    Citation Envoyé par prgasp77 Voir le message
    Salut,

    j'espérais qu'une spécialisation existait qui utiliserait std::string::append .
    J'avais même pas pensé à cette possibilité. Un for each fait le taff
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    std::string result;
    std::vector<std::string> vector{"Hello", ",", " ", "World", "!"};
     
    for(auto const& str: vector) {
    	result.append(str);
    }

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

Discussions similaires

  1. error: ‘wstring_convert’ is not a member of ‘std’
    Par Nouri2012 dans le forum Langage
    Réponses: 6
    Dernier message: 19/06/2012, 16h37
  2. sort is not a member of std
    Par maryem_kh dans le forum SL & STL
    Réponses: 4
    Dernier message: 14/04/2012, 13h17
  3. Error 2039 'set' : is not a member
    Par yves042 dans le forum C++
    Réponses: 1
    Dernier message: 01/06/2010, 12h44
  4. [VB6]Error 76: path not found
    Par riesseg dans le forum VB 6 et antérieur
    Réponses: 29
    Dernier message: 29/05/2006, 22h59
  5. Réponses: 2
    Dernier message: 25/12/2005, 20h03

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