If I have a stream that has coordinates of a point that are being added together, is there any way I can read in the doubles in the stream into specific variables and also be able to get the operator?
For example, if I read in "(3.0,4.7) + (5.3,6)", how can I store the 3.0 and 4.7 into specific variables, get the operator, and store the 5.3 and 6 into other variables?
It's the first time I'm using streams in C++ so I'm not sure how to read from them and didn't find help through google, thank you for your time.
First, read "(3.0,4.7) + (5.3,6)" from the stream using getline and insert it into a string. Now, notice that each number is preceded and followed by a parenthesis or a comma. So you could make a program that will go through each element of the string containing "(3.0,4.7) + (5.3,6)", and if the element is a comma or parenthesis, then have the program copy every element that follows into another string until the next comma or parenthesis is reached. Then, to convert the string to a double, use a stringstream object. That's one way I can think of. And as for the operator, have the program check to see if an element is a plus sign or minus sign or whatever operators you want, and if it finds that operator then just perform the corresponding operation.
EDIT: or you can scan the string for parentheses and commas and replace any occurrences with spaces. This would probably be a lot easier.
Yeah, that's probably the best way. I first got rid of the junk. And I assumed the stream was a stringstream but now that I think of it it's probably cin; I overcomplicated this :-)