「已注销」 2020-04-12 20:28 采纳率: 0%
浏览 268

输入运算符重载后,为什么不能正常输入?

运算符已经重载完成。但输出k仍然是(0,0)

istream& operator>>(istream& input, Complex&a)
{
    input.ignore(); // skip (
    input >> a.imaginary; // input imaginary
    input.ignore(); // skip,
    input >>a.real; // input real
    input.ignore(); // skip )
    return input; // enables cin >> a >> b >> c;
} // end function operator>> 

int main()
{
    Complex x, y(4.3, 8.2), z(3.3, 1.1), k;
    cout << "Enter a complex number in the form: (a, b)\n? ";
    cin>> k; // demonstrating overloaded >>    
        cout << "x: " << x << "\ny: " << y << "\nz: " << z << "\nk: "       
        << k << '\n'; // demonstrating overloaded <<    
    x = y + z; // demonstrating overloaded + and = 
    cout << "\nx = y + z:\n" << x << " = " << y << " + " << z << '\n';    
    x = y - z; // demonstrating overloaded - and = 
    cout << "\nx = y - z:\n" << x << " = " << y << " - " << z << '\n';
    x = y * z; // demonstrating overloaded * and =    
    cout << "\nx = y * z:\n" << x << " = " << y << " * " << z << "\n\n"; 
    if (x != k) // demonstrating overloaded !=       
        cout << x << " != " << k << '\n';    
    cout << '\n';    
    x = k;    
    if ( x == k ) // demonstrating overloaded ==      
        cout << x << " == " << k << '\n';    
    return 0;
}

输出如下
图片说明
输入了(2,3),但k输出仍为(0,0)

  • 写回答

2条回答 默认 最新

  • dabocaiqq 2020-04-15 00:45
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配