我不断收到错误,没有构造函数可以采用源类型或构造函数重载解析。
在我的代码开头,我宣布了一个无序的地图。
unordered_map<char * , a_dictionary * > Mymap;
unsigned char hash[20];
char hex_str[41];
string answer, line;
int yes=0;
cout<<"Press 1 if you would like to use the default file(d8.txt) or press 2 if you want your own file"<<endl;
getline(cin,answer);
stringstream(answer)>> yes;
if(yes == 1 )
{
ifstream myfile("d8.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
//cout<<line<<endl;
a_dictionary * dic = new dictionary();
dic->word = line;
const char * c= line.c_str();
sha1::calc(c,line.length(), hash);
sha1::toHexString(hash,hex_str);
Mymap.insert(hex_str, dic); //
这里的行“mymap.insert”一直给我错误错误C2664:'std :: _ List_iterator&lt; _Mylist&gt; std :: _ Hash&lt; _Traits&gt; :: insert(std :: _ List_const_iterator&lt; _Mylist&gt;,_ Valty)即使我传递了正确的值吗?
这是调用HeXString
的函数void toHexString(const unsigned char* hash, char* hexstring)
{
const char hexDigits[] = { "0123456789abcdef" };
for (int hashByte = 20; --hashByte >= 0;)
{
hexstring[hashByte << 1] = hexDigits[(hash[hashByte] >> 4) & 0xf];
hexstring[(hashByte << 1) + 1] = hexDigits[hash[hashByte] & 0xf];
}
hexstring[40] = 0;
}
答案 0 :(得分:0)
您需要将其作为一对插入。
Mymap.insert(std::make_pair(hex_str, dic));
或使用C ++ 11初始化列表
Mymap.insert({hex_str, dic});
查看示例here
或者,您可以使用operator[]
,从而产生更清晰的代码
Mymap[hex_str] = dic;
答案 1 :(得分:0)
http://cplusplus.com/reference/unordered_map/unordered_map/insert/ 检查插入声明。你想要std :: pair。