Output problem with hiragana, wchar_t and unicode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Karsas
    New Member
    • May 2010
    • 1

    #1

    Output problem with hiragana, wchar_t and unicode

    I am trying to write a little program for myself, which is supposed to help with learning hiragana (some kind of japanese characters)
    At one point the program is supposed to output a wchar_t which holds some hiragana characters. Let's use the following as an example:

    wchar_t Hiragana[] = L"あいうえおかきくけこさしす せそ";

    I tried many different things so far, the bestworking were:

    1) for (int i=0; i<15; i++) cout << " " << Hiragana[i];

    2) ofstream myfile;
    myfile.open ("Hiragana.html ");
    for (int i=0; i<15; i++) myfile << " " << Hiragana[i];
    myfile.close();


    3) FILE * pFile;
    pFile = fopen ("hiragana.html ","w");
    fwrite(Hiragana , sizeof(wchar_t) , 15, pFile);
    fclose(pFile);


    The first 2 are giving me the corresponding unicode numbers of the hiragana characters. When I exchange cout with wcout and ofstream with wofstream none of them outputs anything.
    The third solution outputs a strange string like D0[0G0 etc. (a total of 15 symbols with a 0 attached, one for each hiragana character).

    So my question is: what do I have to do to output hiragana characters? My guess is that the problem is with the output font, but I don't know how to handle fonts at all.

    PS: I don't care if the output is in the console, a txt or a html file
    PS²: I'm using Visual C++ 2008 Express Edition on Windows 7 64 Bit
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Is this for Windows? If so, you will need to read up on localization. In effect, you use an identifier in your code that is processed at build time against a database of supported local languages. The correct local language is substituted for your identifier at build time. Then when you display in your window you have the correct phrase.

    This should all be MSDN. There is also info in Windows via C/C++ by Jeffrey Richter.

    You would have a build for each supported local language.

    wcout does not know about this so you get nothing or garbage output.

    Comment

    Working...