Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I have been playing with utf32 characters and I cannot get the following working: Code: #include <iostream> using namespace std; int main(int argnum, char *argstr[]) { wprintf(L"test\n"); setlocale(LC_CTYPE,"th_TH"); wchar_t ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    19

    c++ wchar_t

    Hello,
    I have been playing with utf32 characters and I cannot get the following working:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(int argnum, char *argstr[])
    {
    	wprintf(L"test\n");
    	setlocale(LC_CTYPE,"th_TH");
    	
    	wchar_t c=0xe5b;//L'ข';
    	unsigned long test = (unsigned long)c;
    	
    	wcout<<L"value "<<test<<endl;
    	wprintf(L"hex: %lc %x\n",c,test);
    	return 0;
    }
    The problem is that
    Code:
    wprintf(L"hex: %lc %x\n",c,test);
    always returns "hex: ? e5b" (the question mark is the issue).

    Can anybody please tell me what is incorrect in my code?
    thanks in advance,
    Regards Meereck

  2. #2
    Just Joined!
    Join Date
    Aug 2007
    Posts
    7
    Hi,

    Two things jump out at me.

    1. The size of wchar_t is implementation dependent. On all of the platforms I've worked with, wchar_t is actually 16 bits, not 32bits.

    2. Just because you can specify a unicode character by hex value, doesn't mean your OS actually has anything to map it to. Do you have that language installed on your machine? If not that may explain the question mark.

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    19
    Hi,
    I think it is 32bit on my Ubuntu 9.10 32bit:
    Code:
    wchar_t c=0xe5b;//L'ข';
    wcout <<L"size:"<<sizeof(c)<<endl;
    Returns 4

    2) Hmm, you are right, I think that is the cause

    Thank you
    Regards Meereck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...