c++ Convert ascii to char?

Started by
2 comments, last by johnnyBravo 19 years, 10 months ago
Hi, ive got ascii codes that i want to convert to char in c++ any ideas? , thanks
Advertisement
char letter = (char)ascii; // ???

[ CodeDread ]
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)
#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