呼叫运营商<<在gdb中 [英] calling operator<< in gdb
问题描述
你如何从gdb中调用运算符<<(std :: ostream& os,const ClassX& x)
?
换句话说,你如何在gdb中打印一个对象?
call std :: cout 或
调用操作符<<(std :: cout,x)
似乎不适用于我!
有什么想法?
我发现的唯一方法是:
call'operator<<(std :: ostream&,myclass&)'(mycout,c)
由于某些原因,
std :: ostream mycout(std :: cout.rdbuf());
您没有说明想要这样做的任何理由,但不会打印你的变量
更容易?
如果这是绝对必须的,你可以在你的类中有一个 Print
方法,并从 operator<
然后从gdb调用对象的 Print
方法。
请注意stdout可能在gdb中被缓冲,所以除非您以某种方式重定向它,否则您将看不到任何输出。
请参阅这篇来自gdb的邮件存档关于这个问题的讨论。
How do you call operator<<(std::ostream &os, const ClassX &x)
from inside gdb ?
In other words, how do you print an object in gdb ?
call std::cout<<x
or call operator<<(std::cout, x)
don't seems to work for me!
Any ideas?
The only way I found was this:
call 'operator<<(std::ostream&, myclass&)'(mycout, c)
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());
You haven't stated any reasons for wanting to do this but won't print yourvariable
be easier?
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.
Do take note that stdout is probably buffered in gdb so you won't be seeing any output unless you redirect it somehow.
See this discussion from gdb's mailing archive regarding this issue.
这篇关于呼叫运营商<<在gdb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!