c++ Convert ascii to char?
A char is actually the ASCII value You can make C++ display the value as a number, by typecasting it to an integer.
char ca = ''a'';
int ia = (int)ca;
--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net''s DirectX FAQ. (not as cool as the Graphics and Theory FAQ)
char ca = ''a'';
int ia = (int)ca;
--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net''s DirectX FAQ. (not as cool as the Graphics and Theory FAQ)
#include <string>#include <sstream>#include <iostream>int main() { std::string ascii("93"); std::stringstream ss; ss << ascii; int n; ss >> n; char c = n; std::cout << c; return 0;}
of course this use of stringstream could be generalised to any type that supported << and >>
[edited by - quorn on June 2, 2004 11:23:17 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement