输出一个在无序映射中的结构变量

时间:2013-02-27 08:21:49

标签: c++ struct output unordered

有没有人知道如何输出一个结构变量,它在一个无序的map.how中我可以得到字典 - > word例如

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 << " , ";
                        }
                    }
                }

1 个答案:

答案 0 :(得分:1)

迭代器的second成员是指向a_dictionary结构的指针,因此只需像访问普通结构指针一样访问它:

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