How to print Unicode(wchar) characters to console 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
samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 340
Joined: Mon Oct 06, 2008 12:55 pm

How to print Unicode(wchar) characters to console

Post by samsam598 »

Hello eveyone!

A simple question again but it is still hard to me.Try to print a welcome msg to console,using both wxPuts and wxPrintf to print an unicode string,say Chinese characters just faied.Nothing printed:

wxWidget2.9.1 Unicode build under Windows XP:

#include <wx/wx.h>
void main()
{
wxPuts(wxT("欢迎来到中国!"));
wxPrintf(wxT("欢迎来到中国!"));
wxGetchar();
}
Could anybody figure me out what is the right way to print Chinese characters to console in wx?Thanks a lot.

Regards,
Sam
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

Have you tried

Code: Select all

wxString msg(wxT("欢迎来到中国!")); 
std::cout << msg.mb_str() << std::endl;

this?

On linux, it works fine (Ubuntu -Jaunty, g++-4.4.0).
Sorry, i have no windows to try.

Regards

Orbitcowboy
samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 340
Joined: Mon Oct 06, 2008 12:55 pm

Post by samsam598 »

[quote="orbitcowboy"]Have you tried

Code: Select all

wxString msg(wxT("欢迎来到中国!")); 
std::cout << msg.mb_str() << std::endl;

Thank you so much for your help.

The above code works.

But I am curious now isn't there such an equivalent method in wxWidgets?One has no other choice to do such task except importing std namespace?

Regards,
Sam
orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy »

samsam598 wrote:
orbitcowboy wrote:Have you tried

Code: Select all

wxString msg(wxT("欢迎来到中国!")); 
std::cout << msg.mb_str() << std::endl;

Thank you so much for your help.

The above code works.

But I am curious now isn't there such an equivalent method in wxWidgets?One has no other choice to do such task except importing std namespace?



Regards,
Sam
I hope i understand you correctly... The msg.mb_str() is a wxWidgets function..
I recommend to read this wiki page, it helped me a lot.

http://wiki.wxwidgets.org/WxString

Best regards

Orbitcowboy
Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver »

samsam598 wrote:
But I am curious now isn't there such an equivalent method in wxWidgets?One has no other choice to do such task except importing std namespace?

Regards,
Sam
No it isn't. The only way is to use cout from the c++ standard library.
But it is c++ integrated, and you can use it from everywhere by using std:: so I don't know where is the problem.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3
samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 340
Joined: Mon Oct 06, 2008 12:55 pm

Post by samsam598 »

[/quote]

No it isn't. The only way is to use cout from the c++ standard library.
But it is c++ integrated, and you can use it from everywhere by using std:: so I don't know where is the problem.[/quote]

I do know no problem using std in general.I rememberd in the wx Doc or somewhere I read that import stl should be avoided since it will largely delay the compiling time and increase the code size(Please correct me if I am completely wrong),this is why I have such a question.I mixed stl and std in mind at that moment.Sorry for such a mess!

Best Regards,
Sam
Post Reply