我有这个函数接收const vector
个<unsigned int, 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();
}
在使用// ERROR
选择的行中,我收到以下错误:
error: no match for ‘operator<<’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘const unsigned int’)
我不知道问题是什么,因为stringstream应该将unsigned int转换为string。
有任何帮助吗?我使用的是C ++ 98
答案 0 :(得分:4)
ss << ((idPair->first == myPairsList.begin()) ? "" : ",") << idPair->first;
^ ^
添加父母
没有它们,这就是它试图做的事情:
ss << (idPair->first == myPairsList.begin()) ? "" : "," << idPair->first;
~~~~^^~~~~~~~~~~~~~~