It looks like Thomas Matthews has provided how to do what it looks like you're trying to do, so I'll just explain why what you tried doesn't work.
The data types are the the same, double
, but the value categories are not. std::complex::real()
returns an un-assignable prvalue, not an assignable lvalue.
The value returned by a[i].real()
only exists for the blink of an eye, the end of the line, so assigning to it is completely useless. The C++ standard requires the compiler to reject the assignment to prevent the errors that would result.
You could use the std::complex::real(double)
overload
a[i].real(lines[i]);
But use the other answer. It will result in much less grief.
Further reading: What are rvalues, lvalues, xvalues, glvalues, and prvalues?