i want to read an array of complex numbers (in a+bi
form). There are several suggestions I found on the internet, however those methods only result the re
Your requirement (the format of input you seek) does not correspond to the method you are using to read it. The default streaming of a complex is the real and the imaginary part separated by spaces and in brackets - the sign between is not mandatory, and the trailing i
is not required.
The obvious way to parse for input you seek is to read the real part, read a character, check if the character is a signed (+
or -
) and ignore spaces, then read the imaginary part. That is trivial with istream
s.