I have a USB string descriptor in a uint8_t array. For example:
0000:12 03 34 00 45 00 36 00 31 00 42 00 43 00 30 00 ..4.E.6.1.B.C.0.
0010:30 00 0.
(The first two bytes are the length and descriptor type; the remaining bytes are the uint16_t characters.)
I would like to print this on the terminal with as little hassle as possible, and preferably without having to screw around with all the other printing (which happens like cout << "Hello, world" << endl;
)
In particular, I would like to do:
cout << "Serial number is: " << some_cast_or_constructor( buf + 2, len - 2 ) << endl;
and for the string descriptor above, get the following on a terminal:
Serial number is: 4E61BC00
Is this possible, or do I have to delve into Unicode arcana?
[edit to add:]
Per @PaulMcKenzie, I tried this program:
#include <iostream>
#include <fstream>
#include <exception>
#include <string>
#include <locale>
int
main( int argc, char **argv )
{
char buf[] = { 34, 00, 45, 00, 36, 00, 31, 00, 42, 00, 43, 00, 30, 00, 30, 00 };
std::wcout << "Hello" << std::wstring( (const wchar_t *)buf, sizeof(buf) ) << std::endl;
return 0;
}
The output:
user:/tmp$ g++ foo.cc
user:/tmp$ ./a.out
Hello??????????
user:/tmp$