c++ - 输出无序映射中的结构变量

标签 c++ struct output unordered

有谁知道如何输出一个无序映射中的结构变量。我怎么能得到字典->例如单词

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;

关于c++ - 输出无序映射中的结构变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15107208/

相关文章:

PHP Delete 返回错误

javascript - 范围数生成器

c++ - QObject::connect 的函数包装器

struct - 是否有将默认名称放入元组中以获得更好的代码完成和建议的功能?

c# - 字典中的组合键;覆盖 GetHashCode()、Equals 等还是使用结构?

c - memset(&mystruct, 0, sizeof mystruct) 和 mystruct = { 0 }; 一样吗?

带文件的 C 项目

c++ - 对于在 Linux 中正常构建的 C++ 程序,VS2010 中的编译失败

c++ - 不同数据类型的sizeof(datatype pointer)/sizeof(data type)取值不同,为什么?

c++ - 通过指针访问数组