![](/img/trans.png)
[英]Is it possible to access the real and imaginary parts of a complex number with the [] operator in C++
[英]GDB - Accessing real and imaginary parts of a complex number
在调试使用(C或C ++)的程序时, gdb
复数显示为_M_value = xxx + yyy*I
(具有complex double
的类型)。
在调试时,我需要打印该数字乘以一个因子。
以下不起作用 :
print a * 8.0
Argument to arithmetic operation not a number or boolean
。
此外,我无法访问实部和虚部,以便我可以编写一个gdb宏来执行上述操作。 我目前的解决方案是编写一个C函数来处理复杂的值和数组,并从gdb调用该函数。 不知何故,这感觉不对。
如果使用标准C ++复杂模板,那么complex :: real()和complex :: imaj()应该可以工作。
MY2C
注意:是评论^^
您可以调用C库函数creal()
和cimag()
来分解数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.