Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:29:04+00:00 2026-05-14T07:29:04+00:00

im tyring to get this to work: #define UNICODE #define _UNICODE #include <wchar.h> int

  • 0

im tyring to get this to work:


#define UNICODE
#define _UNICODE
#include <wchar.h>

int main()
{
    wprintf(L"Hello World!\n");
    wprintf(L"£안, 蠀, ☃!\n");
    return 0;
}

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:

C:\dev\unicodevs\unicodevs\Debug>unicodevs.exe
Hello World!
┬ú∞
C:\dev\unicodevs\unicodevs\Debug>

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:

C:\dev\unicodevs\unicodevs\Debug>cmd /u /c "unicodevs.exe > output.txt"

the file produced (even though its UTF-8 encoded) looks like:

Hello World!
壓

the source file itself is defined as unicode (encoded in UTF-8 without BOM).
the compiler output when building:

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 ==========

any ideas on what am i doing wrong ?
similar questions on ST (like this one: unicode hello world for C?) seem to refer to *nix builds – as far as i understand setlocale() is not available for windows.

i also tried building this using code::blocks/mingw gcc, but got the same results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:29:05+00:00Added an answer on May 14, 2026 at 7:29 am

    It’s not the writing (wprintf) that’s the problem, it’s the cmd redirection of output that’s causing the problem. You can try testing by writing directly to file instead. In that case, you might then run into notepad (or rather Windows API function) not guessing correctly and interpreting your text as ASCII incorrectly if you’re just writing a couple of words. In which case, you’ll need to write the BOM characters into the file first as well.

    #include <stdio.h>
    #include <wchar.h>
    
    int main()
    {
        FILE *out;
        char bom[] = "\xFF\xFE";
        wchar_t s[] = L"中文!";
        size_t c;
    
        out = fopen ("out.txt", "w");
        if(out == NULL)
        {
            perror("out.txt");
            return 1;
        }
    
        c = fwrite(bom, 1, 2, out);
        if(c != 2)
        {
            perror ("Fatal write error.");
            fclose(out);
            return 2;
        }
    
        c = fwrite(s, sizeof(wchar_t), wcslen(s), out);
        if(c != wcslen(s))
        {
            perror ("Fatal write error.");
            fclose(out);
            return 2;
        }
    
        fclose(out);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get unicode working on windows in a visual studio 2k8
I am trying to define a mapping for Ctrl + . as follows: map
I am trying to define a WCF contract that returns an interface, something like
I'm trying to build some image algebra code that can work with images (basically
i need some advice and help with a plugin i am writing for Nagios.
Well I had Tomcat 6 up ad running for a long time and then
The following code fails to compile stating A local variable named 'st' cannot be
Here's an interesting problem that I have just come across. It is possible to
I'm looking to create a rich-featured application using a client/server model, using WCF as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.