overload insertion operator<< ::: UPDATED!!!
Hey Guys, Just gotta say ive been reading through the forums for about a month, you do a great job!
I am pretty new to C++, so excuse my newbieness
My question involved overloading the insertion operator.
What i need to do is read in a complex number in form (a, b)
but i need to allow it to have arbitrary whitespace anywhere in the form and still read correctly like:
( a , b )
any incorrect form is just returned as (0, 0).
Input this could be coming in from a file formed something like this:
(
(3, 4)
5, 6)
(5 7)
(3 , 7 )
The only problem I run into is shown above.
First i compare the first character for '('
get "realPart of complex number"
compare for a ','
get "imaginary part of complex number"
compare for ')'
ignore rest until newline (unless current character is newline)
I run into the problem on the input
(
because, it tries to read in the Real Part, finds nothing, hits newline, then goes to next line, and starts reading that input!
essentially it skips the second input and screws up that reading.
Is there any way to get it to STOP reading for realPart once it hits a newline?
or is my approach completely wrong??
Thanks for any help!!!
Hey Guys, Just gotta say ive been reading through the forums for about a month, you do a great job!
I am pretty new to C++, so excuse my newbieness
My question involved overloading the insertion operator.
What i need to do is read in a complex number in form (a, b)
but i need to allow it to have arbitrary whitespace anywhere in the form and still read correctly like:
( a , b )
any incorrect form is just returned as (0, 0).
Input this could be coming in from a file formed something like this:
(
(3, 4)
5, 6)
(5 7)
(3 , 7 )
The only problem I run into is shown above.
First i compare the first character for '('
get "realPart of complex number"
compare for a ','
get "imaginary part of complex number"
compare for ')'
ignore rest until newline (unless current character is newline)
I run into the problem on the input
(
because, it tries to read in the Real Part, finds nothing, hits newline, then goes to next line, and starts reading that input!
essentially it skips the second input and screws up that reading.
Is there any way to get it to STOP reading for realPart once it hits a newline?
or is my approach completely wrong??
Thanks for any help!!!
Last edited: