• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

dumbass newbie c++ question

Thom

Platinum Member
Okay, i know, this is probably real easy...but call me stupid.

how do i typecast a (char) into a (int) and get a decent value

for example if i have a char[2] "10" how to i typecast it into an integer=10

Thanks, i know i am probably stupid.

 
ummm, I don't know c++, but I do know that "10" is a string and not an char 🙂

I think you have to get each char of the string starting from the right and multiply it by the right power of 10. (in the case 223, you have 3 x 10 ^ 0 + 2 x 10 ^ 1 + 2 x 10 ^ 2)

And if it just an ascii value like "1" or "2", you just have to subtract the right value from the ascii code (which you get when you do just a (int) cast.) So if you get 9999 for a value of 1, then subtract 9998 from it and you get the right values for 2, 3, 5,6 , etc... but I don't have the ascii chart memorized right off hand 🙂
 
i've yanked the char out of a text file using ifstream. it will happily display the number if it is char[x]. so i don't think, (not that i have a clue) it's a string in that sense.
 
er, okay, captain dumbass over here just changed the datatype to a int initially, and the problem went away. god i am stupid. cheers anyway mate. 😀
 
Back
Top