Displaying í and the other latin chars..how? Topic is solved

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
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Displaying í and the other latin chars..how?

Post by Joelito »

This is my current code to test my problem:

Code: Select all

#include <wx/string.h>

int main() {
	wxPuts(wxT("García")); // Displays "Garc?a"
	return 0;
}
How can I print the correct string: "García"?
Thanks.
Double Trouble
Knows some wx things
Knows some wx things
Posts: 26
Joined: Sat Jun 14, 2008 12:42 pm
Location: Sweden
Contact:

Re: Displaying í and the other latin chars..how?

Post by Double Trouble »

Joelito wrote:This is my current code to test my problem:

Code: Select all

#include <wx/string.h>

int main() {
	wxPuts(wxT("García")); // Displays "Garc?a"
	return 0;
}
How can I print the correct string: "García"?
Thanks.
The problem is probably the encoding of the source file (main.cpp or what you're calling it)! You should save in with the encoding Unicode (UTF-8 with signature) !

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

Post by Auria »

Or look up Unicode tables and escape the character

"blah blah \Ux0085 blah blah"

Or write the app in english and use i18n to get translations
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Did you try to use the _ macro instead of wxT ?

Code: Select all

wxPuts(_("García")); 
masteryoda
Earned a small fee
Earned a small fee
Posts: 16
Joined: Wed Jan 23, 2008 11:18 pm

Post by masteryoda »

Auria wrote:Or look up Unicode tables and escape the character

"blah blah \Ux0085 blah blah"

Or write the app in english and use i18n to get translations
Auria, I tried to do a wxT("whatever\Ux00E0whatever") but it didn't work, can you give me a valid example?

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

Post by Auria »

I was writing that from the top of my memory, look-up unicode tables for the real character codes (e.g. http://www.fileformat.info/info/unicode/char/search.htm)

A valide example :

Code: Select all

wxT(" Non-english character : \u00FC")
Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank »

I don't know about Unix, but on Windows the Console has another Codepage than the GUI (437 or something).

So, a String that is perfectly fine in a GUI app will be garbage in the console.

I never used Unicode, so dunno if it matters in Unicode-Build.
michel
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Jun 20, 2008 9:45 am

Post by michel »

hello,

In windows console, you can specify the codepage with the command "chcp" :

in program :

Code: Select all

system("chcp 1252");
_setmbcp(1252);
printf("García");
system("pause");
be sure to use a TrueType font (see the console properties)
that is enable to display wide characters.

A second thing that could help :

with gcc compiler, you can specify the codepage of the editor, with the option : -finput-charset=CP1252
By default, utf8 is used.

With msw compiler, I guess it is CP1252.


Michel
Post Reply