slour wrote: |
---|
I haven't learned about the & signs yet so I'm not sure of their function, |
A
std::ostream& is a reference to
std::ostream. A reference may refer to any class which is derived from the type named in the declaration. For instance, a
std::ostream& can refer to an object of type
std::ostream, such as
std::cout or an object of type
std::ofstream such as
fout in my code above.
I don't have the file that you're working with, so I made it easier to test my code with console input. You could easily do a search replace
in and
out with
std::cin/
std::cout or
fin/
fout. There's nothing magical going on there.
slour wrote: |
---|
and the reason I had the + sign in with the mult int is that the * sign would not allow the program to function the way it was written. |
That doesn't make much sense to me. Perhaps being more explicit with actual (attempted) code would help.
slour wrote: |
---|
Also why does the code disregard the num1 integer the way I have it written? |
When you use the comma operator, the first of the comma separated expressions is evaluated and the result is discarded. Then the next expression is evaluated and the value of the statement becomes the value of the last expression evaluated.
So, in: (Extra parentheses added for clarity)
1 2
|
while ((num1), (num2 >> x))
add += x,mult *= x;
|
num1 is evaluated and discarded and the value of the control expression for the while loop becomes just
num2>>x
.
slour wrote: |
---|
I have been reading up on isdigit and thing that is the way I want to go. |
For most programs such as this simply trying to extract a number from the input stream and noting whether the extraction succeeded or failed is enough.
isdigit operates on individual characters. Feeding it a
std::stringstream is not feeding it an individual character.