char c = '4';
int i = c - '0';
cout <
Convert character to number in c++
Quote:Original post by Anonymous Poster
char c = '4';
int i = c - '0';
cout <
Nice. Reminds me of the old converting decimal to hex by indexing into an array of "1234567890ABCDEF".
Not only does this do the wrong thing, it crashes (for me, anyway)
That'll teach me to modify read-only memory.
int main() { static const int c = 0; const_cast<int &>(c) = 42; }
That'll teach me to modify read-only memory.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement