Unicode characters in console-application.

I'm writing a program that prints the date in different languages,
but it dosn't work with languages that uses the Unicode Character Set.

Here's the source-code:
#include <iostream>
#include <locale>
#include <time.h>

using namespace std;

int wmain(void)
{
wchar_t date[81];
time_t currentTime;
struct tm tmTime;

time(&currentTime);
gmtime_s(&tmTime, &currentTime);
_wasctime_s(date, 80, &tmTime);

locale swedish("swedish");
locale::global(swedish);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Svenskt datum: \n";
wcout << date << endl << endl;

locale norwegianBokmal("norwegian-bokmal");
locale::global(norwegianBokmal);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Norskt datum (Bokmal): \n";
wcout << date << endl << endl;

locale norwegianNynorsk("norwegian-nynorsk");
locale::global(norwegianNynorsk);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Norskt datum (Nynorsk): \n";
wcout << date << endl << endl;

locale finnish("finnish");
locale::global(finnish);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Finskt datum: \n";
wcout << date << endl << endl;

locale danish("danish");
locale::global(danish);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Danskt datum: \n";
wcout << date << endl << endl;

locale french("french");
locale::global(french);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Franskt datum: \n";
wcout << date << endl << endl;

locale german("german");
locale::global(german);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << "Tyskt datum: \n";
wcout << date << endl << endl;

locale chineseSimplified("chinese-simplified");
locale::global(chineseSimplified);

wcsftime(date, 80, L"%#x", &tmTime);
wcout << L"Kinesiskt datum (f?renklad): \n";
wcout << date << endl << endl;

return 0;
}

[2442 byte] By [Pansar_Nisse] at [2007-12-18]
# 1
What VS version are you using?
MartinRichter at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2
VC++ 2005 Express Edition.
Pansar_Nisse at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3
Does the console support Unicode?
(My OS is Windows XP Pro (swedish)).
Do I have to change the default font?
Pansar_Nisse at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 4

Hi I write simple C# program for testing unicode , but my console dosent support , What can I do ? I wantto display ??r?n?a

unicode character.

code is following ,

using System;

using System.Collections.Generic;

using System.Text.RegularExpressions;

namespace ConsoleApplication2

{

class Program

{

static void array()

{

string test = "??r?n?a";

Console.WriteLine(test);

}

static void Main(string[] args)

{

array();

}

}

}

sinankoylu at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 5

The console is still codepage based and it works off of the language for none Unicode programs set on your system as far as I know.

You can programatically change the codepage of the the console to the codepage you want though.

crescens2k at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 6

It seems to me that the problem is stdout, not the console.

I tried wpfrintf and wcout and could not print unicode chars.

But, with _cwprintf I was able to output everything perfectly!

Zvuk at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 7

Did you mean using SetConsoleOutputCP API?

But how can I set console codepage as Unicode, I try to set it by the following statement:

:Tongue TiedetConsoleOutputCP(1200); But failed and GetLastError() = 87 (The parameter is incorrect.)

VeblenLee at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...