unsigned char print

Hi, how do I print an unsigned char in c++?

e.g.

1
2
3
4
unsigned char a[100] = "acdef";

wprintf(L"a is %u\n", a);
wcout << "a is " << a << endl;


gives

1
2
3
a is 2880488
a is 002BF3E8


and not

1
2
a is acdef
a is acdef


??

what is the difference between unsigned char and char?
Last edited on
Wcout << a; a is not a wide character string.
Last edited on
if I do

1
2
unsigned char a[100] = "acdef";
cout << "a is " << a << endl;


the program crashes :s without any output

I am also using
 
_setmode(_fileno(stdout), _O_WTEXT); // MSVC's special needs 

because I also need to output wide characters. How can I do this, and, also, still use non-wide characters in output?
Last edited on
Why do you use unsigned char instead of char?
Standard 3.9.1.1
Plain char, signed char, and unsigned char are three distinct types.

And output streams can work differently if different data types are presented.
Last edited on
because I have a function, that I didn't write myself, that needs an unsigned char :s
A) Why are you using %u? it is for unsigned integers. You should use %s for c-strings.
B) Use wcout << "a is " << reinterpret_cast<char*>(a) << endl;
Last edited on
aha, that works! thanks! :)
Topic archived. No new replies allowed.