addition of char?

Hi! I am trying to learn C++. I have a question about addition of addition of char. I have made a class called SuperInt. Look at the second last row.
In order to get what I want correct I need to take minus '0'. Note that
temp[i] should be of type int. If I take the '0' away it does not work.
Note also that the pointer q is a pointer to a char.

Does C++ typecast automatically for me in this case or? The strange thing is that
it doesnt even work when I typecase myself, but I need to write it like this.

Thanfull for answers!

1
2
3
4
SuperInt temp(teck == '-', strlen(q));
    for (int i=temp.langd() -1; i>=0; i--)
      temp[i] = *q++ - '0';
    b = temp
closed account (o1vk4iN6)
Why not use BCD instead, that way you only use half the bits.

As well, think of what the outcome will be.

('0' - '0') != '0'
Yes it is casting it for you when you do arithmetic.

The int value of the character '0' is 48.
The int value of the character '1' is 49.
The int value of the character '2' is 50.
... and so on.

If you want to convert the character '7' (55) to the integer 7 then subtract '0' (48).

There are other ways, but this is essentially what you are doing; and it works.
@xerzi: of course, '0'-'0'='\0', like in regular arithmetics, x-x=0!
closed account (o1vk4iN6)
x = infinity

don't think it's zero :P

Anyways, if OP is still here, post your SuperInt class. It would be better to just make a constructor for SuperInt take in a const char* to make your code cleaner.
Topic archived. No new replies allowed.