How to convert number to char c++ win32

I want to convert the number 65 to the letter A
I tried : char s = 65 but still output 65
The ASCII encoding for 'A' is 65 - which is how 'A' is stored internally. How it is displayed is down to output formatting.

Consider:

1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
	const char s {65};
	const char s1 {'A'};

	std::cout << s << ' ' << s1 << '\n';
	std::cout << static_cast<int>(s) << ' ' << static_cast<int>(s1) << '\n';
}


Which displays:


A A
65 65

//C++ WIN32 Console

1
2
const char s{ 65 };
MessageBox(NULL, L"char = " + std::to_string(s), L"", MB_OK);


still out 65

const char s[] = {65,0};
Messagebox(s); //whatever else you need. there are like 20 overloads for message box.
you could also use their halfbaked CString thing.
Last edited on
@ Ba ranh Correct. You're converting the contents of s to a string. s contains 'A' which is the decimal value 65 so the conversion produces 65.

Instead of std::to_string(s), try std::string(1, s)
Thanks seeplus my problem is solved
Topic archived. No new replies allowed.