Unicode

How do I write Unicode on my C++ program, I use the std::cout. I tried doing it put it doesnt work.

For example
 
cout << "电影院"


Shows as ???

It gives me the warning

warning C4566: character represented by universal-character-name '\u5730' cannot be represented in the current code page (1252)

How do I fix this
http://stackoverflow.com/a/2849040
May help you.
1) Windows console uses ASCII by default and doesn't handle unicode characters.
2) Default font doesn't have support for unicode either. (Change it to something non raster)
On Linux and other non-ASCII-friendly systems, both cout << "电影院" and wcout << L"电影院" work just fine, see http://ideone.com/Lvalr9 and http://ideone.com/x5kpK5

On Windows/Visual Studio (which appears to be what you're using, based on the warning message), the simplest solution, I believe, is to enable wide character output:

1
2
3
4
5
6
7
8
#include <fcntl.h>
#include <io.h>
#include <iostream>
int main()
{
    _setmode(_fileno(stdout), _O_WTEXT);
    std::wcout << L"电影院\n"
}


The warning you got was simply for the missing L before your string literal.
Last edited on
Thanks, but umm. for the "L" I don't think I really need it because it usually gives me no warning, in my messagebox test program, when I add L, it doesn't work, but when I remove it it does but thanks!
Topic archived. No new replies allowed.