Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to write unicode hello world in C on windows
    primarykey
    data
    text
    <p>im tyring to get this to work:</p> <pre><code> #define UNICODE #define _UNICODE #include &lt;wchar.h&gt; int main() { wprintf(L"Hello World!\n"); wprintf(L"£안, 蠀, ☃!\n"); return 0; } </code></pre> <p>using visual studio 2008 express (on windows xp, if it matters). when i run this from the command prompt (started as cmd /u which is supposed to enable unicode ?) i get this:</p> <pre> C:\dev\unicodevs\unicodevs\Debug>unicodevs.exe Hello World! ┬ú∞ C:\dev\unicodevs\unicodevs\Debug> </pre> <p>which i suppose was to be expected given that the terminal does not have the font to render those. but what gets me is that even if i try this:</p> <pre> C:\dev\unicodevs\unicodevs\Debug>cmd /u /c "unicodevs.exe > output.txt" </pre> <p>the file produced (even though its UTF-8 encoded) looks like:</p> <pre> Hello World! £ì </pre> <p>the source file itself is defined as unicode (encoded in UTF-8 without BOM). the compiler output when building:</p> <pre> 1>------ Rebuild All started: Project: unicodevs, Configuration: Debug Win32 ------ 1>Deleting intermediate and output files for project 'unicodevs', configuration 'Debug|Win32' 1>Compiling... 1>main.c 1>.\main.c(1) : warning C4005: 'UNICODE' : macro redefinition 1> command-line arguments : see previous definition of 'UNICODE' 1>.\main.c(2) : warning C4005: '_UNICODE' : macro redefinition 1> command-line arguments : see previous definition of '_UNICODE' 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wchar.h 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtassem.h 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vadefs.h 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\swprintf.inl 1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wtime.inl 1>Linking... 1>Embedding manifest... 1>Creating browse information file... 1>Microsoft Browse Information Maintenance Utility Version 9.00.30729 1>Copyright (C) Microsoft Corporation. All rights reserved. 1>Build log was saved at "file://c:\dev\unicodevs\unicodevs\unicodevs\Debug\BuildLog.htm" 1>unicodevs - 0 error(s), 3 warning(s) ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== </pre> <p>any ideas on what am i doing wrong ? similar questions on ST (like this one: <a href="https://stackoverflow.com/questions/787589/unicode-hello-world-for-c">unicode hello world for C?</a>) seem to refer to *nix builds - as far as i understand setlocale() is not available for windows.</p> <p>i also tried building this using code::blocks/mingw gcc, but got the same results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload