我使用operator<<对于打印,但这不是关于打印,这是关于我崩溃的时候,我想从LLDB提示打印出我的哈希. 我不能打电话给cout<< var因为那不起作用. 是否除了例如链接模板函数本身使用cout<<<那甚至会起作用吗? (我正在尝试,但它不起作用,因为我必须提前知道模板参数类型将为它生成和链接代码的内容)
解决方法 您应该能够检查unordered_map对象本身,而无需在其上调用方法.例如,采取这个简单的程序:
#include <iostream>#include <string>#include <unordered_map>using namespace std;int main() { unordered_map<int,string> map; map[0] = "mary"; map[1] = "had"; map[2] = "a"; map[3] = "little"; map[4] = "lamb"; return 0;}$clang++ -std=c++11 -stdlib=libc++ -g unmap.cpp -o unmap$lldb unmapCurrent executable set to 'unmap' (x86_64).(lldb) break set --name main
为简洁起见,未显示lldb输出
(lldb) proc launch
n输入5次直到返回0;声明
(lldb)Process 18063 stopped* thread #1: tID = 0x1c03,0x0000000100000aea unmap`main + 1082 at unmap.cpp:15,stop reason = step over frame #0: 0x0000000100000aea unmap`main + 1082 at unmap.cpp:15 12 map[3] = "little"; 13 map[4] = "lamb"; 14-> 15 return 0; 16 } 17
然后使用p检查对象:
(lldb) p map[0](std::__1::unordered_map<int,std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char> >,std::__1::hash<int>,std::__1::equal_to<int>,std::__1::allocator<std::__1::pair<const int,std::__1::allocator<char> > > > >::mapped_type) = "mary"(lldb) p map[1](std::__1::unordered_map<int,std::__1::allocator<char> > > > >::mapped_type) = "had"(lldb) quit
你使用的lldb版本会有所不同,因为它一直在改进:
$lldb -versionLLDB-179.5
(即Xcode 5 DP 6命令行包附带的那个)
总结以上是内存溢出为你收集整理的c – LLDB:如何检查unordered_map全部内容,希望文章能够帮你解决c – LLDB:如何检查unordered_map所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)