Page 1 of 1
How to print Unicode(wchar) characters to console
Posted: Fri Jun 05, 2009 2:12 am
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
Posted: Fri Jun 05, 2009 8:01 am
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
Posted: Fri Jun 05, 2009 9:50 am
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
Posted: Fri Jun 05, 2009 11:05 am
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
Posted: Fri Jun 05, 2009 11:31 am
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.
Posted: Sat Jun 06, 2009 1:17 pm
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