输出无序映射内的结构变量

outputting a struct variable that's inside a unordered map

本文关键字:结构 变量 无序 映射 输出      更新时间:2023-10-16

有人知道如何输出无序映射中的结构变量吗?例如,我怎样才能得到dictionary->单词

typedef struct dictionary{ 
std::string word; 
unsigned char hash[20]; 
std::string hex;
 } a_dictionary;
 typedef std::unordered_map<std::string, dictionary*> Mymap;
 std::unordered_map<std::string, dictionary* >::const_iterator got = c1.find(line);
                    if(out.is_open())
                    {
                        if ( got == c1.end() )
                        {
                        out << "????";
                        }
                        else
                        {
                        out << got->first << " , ";
                        }
                    }
                }

迭代器的second成员是指向a_dictionary结构体的指针,所以就像访问普通结构体指针一样访问它:

out << got->first << " , " << got->second->word;