在Mac下默认安装了Xcode是配置好了STL的,像stack,vector,list等基本的类是可以使用的,但在使用
我在尝试着在我的机子上测试如下代码时,发现找不倒hash_compare,该怎么办???
抱歉,自己真的菜鸟一个,我理解mac下的默认是有stl的,但功能可能不全。我调试了
#include
#include
#include
#include
//#include
using namespace std;
using namespace __gnu_cxx;
struct string_less : public binary_function //定义虚函数,以使用hashmap函数
{
public:
result_type operator()(const first_argument_type& _Left, const second_argument_type& _Right) const
{
return(_Left.compare(_Right) < 0 ? true : false);
}
};
int main()
{
hash_map > zhao;
hash_map>::iterator zhi;
hash_map>::iterator qiang;
hash_map>::iterator miss;
hash_map>::iterator you;
//运行监视zhao为{ size=9 }
zhao["a"] = 1;//键a对应值1
zhao["b"] = 2;
zhao["c"] = 3;
zhao["d"] = 4;
zhao["e"] = 5;
zhao["f"] = 6;
zhao["g"] = 7;
zhao["h"] = 8;
zhao["i"] = 9;
zhi=zhao.begin();
//监视显示zhi为("a",1)
cout<first<<" "<< zhi->second<first<<" "; cout<< (zhi)->second<first << "\t" << qiang->second << endl; qiang++;
}
qiang = zhao.end();
//监视内容: <读取字符串的字符时出错。>, -842150451)end应该是最后一个键值对后的空间,将其- -就应该是最后一个键值对
cout<first<first <first << endl;
//输出i。返回一个常量迭代器,此迭代器用于发现反向hash_map中的首个元素。
cout << (--zhao.crend())->first << endl;
//输出a。返回一个常量迭代器,此迭代器用于发现反向hash_map中最后一个元素后的位置。 记得- -哦。
//zhao.clear();
//亲测可用,清除整个hash。
cout<first<first<first<first << endl;
//输出i hash_map中键比指定键大的第一个元素,使用j VS崩溃了。
zhao.erase("k");
//删除掉该键,若不存在则无法删除
cout<second<
bin/../lib/c++/v1/ext/hash_map:209:2: warning:
Use of the header is deprecated. Migrate to
[-W#warnings]
#warning Use of the header is deprecated. Migrate to > zhao;
^
./hash_map_test.cpp:19:38: error: unexpected type name 'string': expected
expression
hash_map > zhao;
^
./hash_map_test.cpp:20:24: error: use of undeclared identifier 'hash_compare'
hash_map>::iterator zhi;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
到底报什么错误你得说出来啊?我的读心术还没有修炼成功,得等到飞升之后才有能力回答这个问题。
Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>说的很明白,不要用
hash_map,用unordered_map;也不要用hash_compare,用std::hash把你现在正学的这本书扔了,换本书重炼。