gpt4 book ai didi

c++ - HashMap 错误: no match for call to ‘(const __gnu_cxx::

转载 作者:行者123 更新时间:2023-12-02 11:02:57 29 4
gpt4 key购买 nike

编译完hash_multimap后,我得到了这么大的一个段落错误
在成员函数“size_t __gnu_cxx::hashtable <

我从未见过如此大的错误,而且由于大小异常,我实际上不确定如何解决此错误。

任何建议为什么行:

p = map1.equal_range(searchKey);

导致此异常长错误?仅供引用-我削减了整个错误并删除了中间部分,因为一旦我将其粘贴到此处,它就像一页纸一样长

错误
/usr/include/c++/4.3/backward/hashtable.h: In member function ‘size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num_key(const _Key&, size_t) const [with _Val =
std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, Map2*>, _Key = std::basic_string<char

...
std::char_traits<char>, std::allocator<char> > >, _Alloc =     
std::allocator<Map2*>]’
hash_map2.cpp:55: instantiated from here
/usr/include/c++/4.3/backward/hashtable.h:595: error: no match for call to
‘(const __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >) (const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)’

Map.h文件
#ifndef MAP2_H
#define MAP2_H

#include <iostream>
#include <string>

using namespace std;

class Map2 {

public:
Map2(string data1, string data2, string data3, string data4, string data5);
string pop, keyword, user, desc, id;

string get_pop() {return pop;}
string get_key() {return keyword;}
string get_user() {return user;}
string get_desc() {return desc;}
string get_id() {return id;}

void call_Values(int i);

};

Map2:: Map2(string data1, string data2, string data3, string data4, string data5) {
pop = data1;
keyword = data2;
user = data3;
desc = data4;
id = data5;
}

void Map2:: call_Values(int i) {

get_pop();
get_key();
get_user();
get_desc();
get_id();
}

#endif

hash_map2.cpp
#include <fstream>
#include <iostream>
#include "Map2.h"
#include <ext/hash_map>
#include <string>
#include <sstream>

using namespace std;
using __gnu_cxx::hash_multimap;

int nav() {
cout <<"Select from the following options : " << endl <<endl;
cout <<"Search Tweets based on Keyword (Type 1) " <<endl;
cout <<"End Program (Type 2)"<<endl<<endl;
int key =0;
cin >> key;
return key;
}

int main() {

int option = nav();

if (option == 1) {
ifstream readFile("project4.csv");
string tempPop, tempID, tempKey, tempUser, tempDesc;
string tempRead;

hash_multimap<string, Map2 *>map1;

while (readFile != NULL){
// sends to a temp variable
readFile >> tempRead;

for (int i =0; i<400; i++){
//create new object each time
Map2 *mapNode = new Map2(tempPop,tempID,tempKey,tempUser,tempDesc);
//insert each time new object is made
map1.insert(pair<string, Map2 *> (tempKey, mapNode));

} //end for
} //end while


//Navigation through multimap
//first pointer is for first one and second to last hash table value
pair<hash_multimap<string, Map2 *> :: const_iterator,
hash_multimap<string, Map2 *> :: const_iterator> p;

string searchKey = "";
cout << "Please enter the keyword value exactly so we can search the"<<
"available tweets: " <<endl;

cin >> searchKey;
p = map1.equal_range(searchKey);







}

else

return 0;
}

最佳答案

问题是调用字符串进行搜索的事实。在调用equal_range函数内部的值之前,需要将字符串转换为int。

关于c++ - HashMap 错误: no match for call to ‘(const __gnu_cxx::,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29973386/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com