Accents in the console on Windows using unicode build

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mathieumg
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Aug 06, 2010 5:16 pm

Accents in the console on Windows using unicode build

Post by mathieumg » Fri Aug 06, 2010 9:26 pm

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!

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Aug 06, 2010 11:22 pm

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?
"Keyboard not detected. Press F1 to continue"
-- Windows

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Fri Aug 06, 2010 11:31 pm

Set the locale and will magically work. I think wx uses it's own wxLocale or something, but std::setlocale() should work as well.

catalin
Moderator
Moderator
Posts: 1578
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Sun Aug 08, 2010 11:00 pm

Maybe you can find something useful here.

mathieumg
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Aug 06, 2010 5:16 pm

Re: Accents in the console on Windows using unicode build

Post by mathieumg » Mon Aug 09, 2010 12:03 pm

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!

Post Reply