How to change the real value of Complex array elements in c++

  c++, complex-numbers

Hey I have a Complex double array and I want to change the values of it from another basic float array, so basically I want to copy all the float array values into the real value of each complex element.

I tried to iterate in a for loop and copy the value but I get errors such lvalue required as left operand of assignment

Here is my code:

typedef std::complex<double> Complex;

const Complex test[] = { 0.0, 0.114124, 0.370557, 0.0, -0.576201, -0.370557, 0.0, 0.0 }; // init the arr with random numbers

for ( i = 0; i < N; i++ )
{
    printf ( "  %4d  %12fn", i, in[i] );
    test[i].real() = in[i]; // this line returns an error
}

can someone please let me know what the correct way of doing so as I’m new to this subject.

Source: Windows Questions C++

LEAVE A COMMENT