Je cette fonction qui reçoit un const vector
de <unsigned int, unsigned int>
paires:C++ erreur stringstream: aucune correspondance pour l'opérateur << pour les types d'opérandes std :: string et const unsigned int
// Type definitions
typedef std::pair<unsigned int, unsigned int> IdsPair;
typedef std::vector<IdsPair> IdsPairList;
typedef IdsPairList::const_iterator IdsPairIterator;
void Foo(const IdsPairList myPairsList){
std::stringstream ss;
ss << "List of ids: (";
for(IdsPairIterator idPair = myPairsList.begin();
idPair != myPairsList.end(); idPair++){
ss << (idPair->first == myPairsList.begin()) ? "" : "," << idPair->first; // ERROR
}
ss << ")";
std::string query = ss.str();
}
A la ligne sélectionnée avec // ERROR
, Je reçois l'erreur suivante:
error: no match for ‘operator<<’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘const unsigned int’)
Je n'ai aucune idée quel est le problème, puisque stringstream est censé convertir l'int en chaîne non signé.
Une aide? J'utilise C++ 98
Mettez ce code : '(idPair-> first == myPairsList.begin())? "": "," 'dans des parenthèses. – sgarizvi
"Méfiez-vous de l'opérateur?: Et mettez-le entre parenthèses" - la première règle ici http://cpphints.com/hints/1 :) –