overload insertion operator<<

Joined
Sep 12, 2006
Messages
2
Reaction score
0
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 :p

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:
Joined
Sep 12, 2006
Messages
2
Reaction score
0
nvm, I ghettoed my way through this assignment, and I think it works 100%!
If anyone is interested in the code I used, tell me :)
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top