calling operatorlt;lt; in gdb(主叫接线员在 gdb 中)
问题描述
如何从 gdb 内部调用 operator<<(std::ostream &os, const ClassX &x) ?
How do you call operator<<(std::ostream &os, const ClassX &x) from inside gdb ?
换句话说,如何在 gdb 中打印一个对象?
In other words, how do you print an object in gdb ?
call std::cout<<x 或 call operator<<(std::cout, x) 似乎对我不起作用!
call std::cout<<x or call operator<<(std::cout, x) don't seems to work for me!
有什么想法吗?
推荐答案
我找到的唯一方法是:
call 'operator<<(std::ostream&, myclass&)'(mycout, c)
由于某种原因 std::cout 对 gdb 不可见,我不得不像这样创建自己的:
Since std::cout wasn't visible to gdb for some reason, I had to resort to creating my own like this:
std::ostream mycout(std::cout.rdbuf());
您没有说明想要这样做的任何理由,但 print yourvariable 会不会更容易?
You haven't stated any reasons for wanting to do this but won't print yourvariable be easier?
如果这是绝对必须的,你可以在你的类中有一个 Print 方法并从 operator<< 调用它,然后调用 Print 来自 gdb 的对象上的方法.
If this is an absolute must you could have a Print method in your class and call that from operator<< and then call the Print method on your object from gdb.
请注意,stdout 可能在 gdb 中缓冲,因此除非您以某种方式重定向它,否则您将看不到任何输出.
Do take note that stdout is probably buffered in gdb so you won't be seeing any output unless you redirect it somehow.
请参阅 gdb 邮件存档中有关此问题的 this 讨论.
See this discussion from gdb's mailing archive regarding this issue.
这篇关于主叫接线员<<在 gdb 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:主叫接线员<<在 gdb 中
基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 常量变量在标题中不起作用 2021-01-01
