1820693 Members
2878 Online
109627 Solutions
New Discussion юеВ

std::wcout not working

 
venkata_1
New Member

std::wcout not working


Host: HP-UX artemis B.11.11 U 9000/800 2599003817
Compiler: aCC: HP ANSI C++ B3910B A.03.73
locale: zh_CN.utf8

Wide character string containing UTF-16 characters does not display on std::wcout but works fine when I use printf with %S.

#include
#include



int main()
{
setlocale(LC_ALL,"");
wchar_t real[25] = {0};

// Original UTF-16 used for checking.
real[0] = 0x003C;
real[1] = 0x65F6;
real[2] = 0x95F4;
real[3] = 0xFF08;
real[4] = 0x7992;
real[5] = 0xFF09;
real[6] = 0x003E;
real[7] = 0x005D;
real[8] = 0x0000;

char src[25] = {0};
// UTF-8 to mach expected output for UTF8 local

src[0] = 0x3c; // 0x003c

src[1] = 0xE6; // 0x65F6
src[2] = 0x97;
src[3] = 0xB6;

src[4] = 0xE9; // 0x95F4
src[5] = 0x97;
src[6] = 0xB4;

src[7] = 0xEF; // 0xFF08
src[8] = 0xBC;
src[9] = 0x88;

src[10] = 0xE7; // 0x7992
src[11] = 0xA6;
src[12] = 0x92;

src[13] = 0xEF; // 0xFF09
src[14] = 0xBC;
src[15] = 0x89;

src[16] = 0x3E; // 0x003E
src[17] = 0x5D; // 0x005D
src[18] = 0x0;

// Using printf
printf("s:%s\n",src);
printf("S:%S\n",real);

// Output the UTF-8

std::cout << "N:" << src << std::endl;

// Output the UTF-16
std::wcout << "W:" << real << std::endl;

return(0);
}

ash-3.00# aCC -AA unicodetest.cpp
7 REPLIES 7
venkata_1
New Member

Re: std::wcout not working

Here is a pic of the output.
Note that the last line contains no visable characters.
Dennis Handly
Acclaimed Contributor

Re: std::wcout not working

It appears you can have any color wchar_t you want, as long as it is black. ;-)

Please contact the Response Center and file a bug report.
venkata_1
New Member

Re: std::wcout not working

I don't know what a "Response Center" center is and I could not find any links, Can you please help where to go(url) or ph # ?
Dennis Handly
Acclaimed Contributor

Re: std::wcout not working

>I don't know what a "Response Center" center is and I could not find any links, Can you please help where to go(url) or ph #?

You need a support contract. Is there anyone in your company that knows about that?
If you have it, there should be links off of the main ITRC page: "remote support and diagnostics"

This page may have some info?
http://welcome.hp.com/country/us/en/contact_us.html

Our contact from RW says there are several issues:
std::wcout has unspecified behavior. There's no requirement that
it use codecvt or even what kind of streambuf it should use
And:
The behavior of codecvt is implementation-defined.

So I suppose you should continue to use stdio or call wcstombs if you have some wchar_t strings and want to use cout.
Dennis Handly
Acclaimed Contributor

Re: std::wcout not working

>Our contact from RW says there are several issues:

Oops, I forgot to mention his solution using imbue:
typedef std::codecvt_byname ucs2utf;
std::wcout.imbue(std::locale(std::locale(), new ucs2utf("zh_CN.utf8")));

Martin Sebor
New Member

Re: std::wcout not working

Or simply:

std::wcout.imbue(std::locale("zh_CN.utf8"));

This way you'll get consistent behavior across all locale categories, including numeric.
Dennis Handly
Acclaimed Contributor

Re: std::wcout not working

Unfortunately Martin's simple fix doesn't work on HP's version of RogueWave stdlib.