简体   繁体   English

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

[英]outputting a struct variable that's inside a unordered map

Does anybody know how to output a struct variable that it's inside a unordered map.how could i get dictionary->word for example 有谁知道如何输出它在无序映射内的结构变量。例如,我如何获取字典->单词

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM