的hash_map [英] hash_map
问题描述
我需要有关哈希映射的帮助。为什么这不起作用:
#include< hash_map>
hash_map< int,string> hm1;
typedef pair< int,string> pr;
hm1.insert(str_pair(1," Hello"));
它编译,但在运行时崩溃,指向xhash中的某些内容。
-
Jon Cosby
请不要回复此电子邮件地址。
I need help in hashmaps. Why doesn''t this work:
#include <hash_map>
hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_pair(1, "Hello"));
It compiles, but crashes at runtime, pointing to something in xhash.
--
Jon Cosby
Please do not reply to this email address.
推荐答案
" Jon Cosby" < QW **** @ abc.net>在留言中写道
news:ps ****************** @ newsread1.news.pas.earth link.net ...
"Jon Cosby" <qw****@abc.net> wrote in message
news:ps******************@newsread1.news.pas.earth link.net...
我需要有关哈希映射的帮助。为什么这不起作用:
#include< hash_map>
hash_map< int,string> hm1;
typedef pair< int,string> pr;
hm1.insert(str_pair(1," Hello"));
它编译,但在运行时崩溃,指向xhash中的某些内容。
I need help in hashmaps. Why doesn''t this work:
#include <hash_map>
hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_pair(1, "Hello"));
It compiles, but crashes at runtime, pointing to something in xhash.
取决于你的无证str_pair的作用。这将是一个非常好的主意,它返回类似的东西:
hash_map< int,string> :: value_type(1,string(")你好));
PJ Plauger
Dinkumware,Ltd。
http://www.dinkumware.com
Jon Cosby写道:
Jon Cosby wrote:
我需要有关哈希映射的帮助。为什么这不起作用:
#include< hash_map>
hash_map< int,string> hm1;
typedef pair< int,string> pr;
hm1.insert(str_pair(1," Hello"));
....此处未定义str_pair。
它编译,但在运行时崩溃,指向xhash中的某些内容。
I need help in hashmaps. Why doesn''t this work:
#include <hash_map>
hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_pair(1, "Hello"));
.... str_pair is not defined here.
It compiles, but crashes at runtime, pointing to something in xhash.
hash_map不是标准的一部分,但它很受欢迎,我没有想到什么是正确的(TM)。在gcc下访问它的方法所以我会检查
。我使用gcc 3.3.1。
以下代码适用于我。也许你的str_pair()返回一个
参考局部变量?
#include< \\ text / hash_map>
#include< ; string>
#include< iostream>
using namespace std;
using namespace __gnu_cxx;
int main()
{
hash_map< int,string> hm1;
typedef hash_map< int,string> :: value_type pr;
hm1.insert(pr(1," Hello" ));
cout<< hm1 [1]<<结束;
}
hash_map is not part of the standard, however it is popular, I have no
idea what the "right(TM)" way to get access to it under gcc so I''d check
up on that. I used gcc 3.3.1.
The code below works find for me. Maybe your str_pair() returns a
reference local variable ?
#include <ext/hash_map>
#include <string>
#include <iostream>
using namespace std;
using namespace __gnu_cxx;
int main()
{
hash_map<int, string> hm1;
typedef hash_map<int, string>::value_type pr;
hm1.insert(pr(1, "Hello"));
cout << hm1[1] << endl;
}
" P.J。 Plauger" < pj*@dinkumware.com>在留言中写道
news:c1 ******************* @ nwrddc02.gnilink.net ...
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:c1*******************@nwrddc02.gnilink.net...
Jon Cosby < QW **** @ abc.net>在消息中写道
新闻:ps ****************** @ newsread1.news.pas.earth link.net ...
"Jon Cosby" <qw****@abc.net> wrote in message
news:ps******************@newsread1.news.pas.earth link.net...
我需要有关哈希映射的帮助。为什么这不起作用:
#include< hash_map>
hash_map< int,string> hm1;
typedef pair< int,string> pr;
hm1.insert(str_pair(1," Hello"));
它编译,但在运行时崩溃,指向xhash中的某些内容。
I need help in hashmaps. Why doesn''t this work:
#include <hash_map>
hash_map <int, string> hm1;
typedef pair <int, string> pr;
hm1.insert(str_pair(1, "Hello"));
It compiles, but crashes at runtime, pointing to something in xhash.
取决于你的无证str_pair所做的事情。
Depends a lot on what your undocumented str_pair does.
这是一个错字。应该只是pr。
Jon
That was a typo. Should be just "pr".
Jon
这篇关于的hash_map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!