MAP和比较类别的C 问题
C ++ Issue with map and the Compare Class
我希望有人可以帮助我解决我的问题。我得到了一个可爱的
无匹配的函数,可以呼叫" const pcompare"的对象
struct pCompare
{
bool operator()( const std::string & str1, const std::string & str2 ) const
{
return str1.compare( str2 ) == 0;
}
};
std::string *t = new std::string ( "/test.html" );
std::map<std::string*, std::string, pCompare> test;
test.insert ( std::pair<std::string*, std::string> ( t, "héhé" ) );
std::cout << test.find(new std::string ("/test.html") )->second;
感谢您的帮助!
首先,不要这样做,因为它会拧紧您的地图:您需要地图的订购功能,而不是相等性测试。
无论如何,我想您的问题是您的密钥类型std :: string*,但是您的功能测试了字符串&amp;。我没有尝试过,但这应该解决:
bool operator()( std::string * str1, const std::string * str2 ) const
{
return *str1 < *str2;
}
相关文章:
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 关于比较两个无序数组并删除 a[] 中可以在 b[] 中找到的元素的问题
- std::max() 函数与定点实现的比较中的问题
- C++复杂情况的比较器通过参数问题
- 这种比较是否不一致(或者存在其他问题)?
- 将此类数据作为字符串进行比较时出现问题
- 关于没有比较的条件的问题
- 通过比较字符设置字符串时出现问题
- 无符号int的比较始终是正确的(NPOS问题?)
- 比较两个字符的问题
- (C++) 学习向量 - 编码/输入流终止/比较向量的问题
- C++ lower_bound比较功能问题
- 比较答案键(C )的字符串的问题
- C++ std:字符串比较编纂问题
- 比较字符串(arduino)时出现问题
- 将 char * 与字符串文本进行比较时出现问题
- MAP和比较类别的C 问题
- 排序功能不起作用(字符串比较问题)
- 使用比较运算符和字符串比较函数读取文本文件的子部分时出现问题
- 使用具有自定义比较类型的关联容器时出现的问题