Page 1 of 1

Accents in the console on Windows using unicode build

Posted: Fri Aug 06, 2010 9:26 pm
by mathieumg
I thought this would help, but it didn't: http://forums.wxwidgets.org/viewtopic.php?t=19525

I'm trying to output words with accents in the console on Windows, I've searched a lot but haven't found a solution for wxWidgets.

Here is my code:

Code: Select all

using namespace std;

#include <string>
#include <iostream>

#include "wx/string.h"
#include "wx/app.h"

int main(int argc, char **argv)
{
    wxInitialize();
    wxPuts(wxT("Bon appétit!"));
}
It outputs: Bon appÚtit!

Is there something I don't do right?

Thanks!

Posted: Fri Aug 06, 2010 11:22 pm
by Auria
See http://www.javajunkies.org/index.pl?nod ... ode_id=717

seems like the windows command prompt is retarded and only accepts some silly DOS encoding.

Maybe check if powershell is any better?

Posted: Fri Aug 06, 2010 11:31 pm
by Frank
Set the locale and will magically work. I think wx uses it's own wxLocale or something, but std::setlocale() should work as well.

Posted: Sun Aug 08, 2010 11:00 pm
by catalin
Maybe you can find something useful here.

Re: Accents in the console on Windows using unicode build

Posted: Mon Aug 09, 2010 12:03 pm
by mathieumg
I've tried the different solutions linked, and so far I've only been able to get one to work:

Code: Select all

using namespace std;

#include <string>
#include <iostream>

#include "wx/string.h"
#include "wx/app.h"

int main(int argc, char **argv)
{
    wxInitialize();
    
    UINT oldcp = GetConsoleOutputCP();
    SetConsoleOutputCP(CP_UTF8);

    wchar_t s[] = L"Bon appétit";
    int bufferSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
    char* m = new char[bufferSize];
    WideCharToMultiByte(CP_UTF8, 0, s, -1, m, bufferSize, NULL, NULL);
    wprintf(L"%S", m);
    delete[] m;

    SetConsoleOutputCP(oldcp);
    return 0;
}
From that, is there a way to simplify things, perhaps make a function/macro, so that things would work by using wxPuts(wxT("Bon appétit!")) or something similar?

Thanks!