* why wxT("%s", c_type_str) print nothing ? 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
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

* why wxT("%s", c_type_str) print nothing ?

Post by whoops »


i'm using wxPuts(wxString::Format(wxT("%s"), c_type_str)); to print c-type string, but it print nothing:

Code: Select all

#include <wx/wx.h>
#include <iostream>
int main()
{
	wxInitializer wx;
	if( !wx.IsOk() ) return -1;
	unsigned char buffer[80] = "Guten Tag!";
	// cout for debug print
	std::cout << buffer << "\n";
	// why %s printf nothing ?
	wxPuts(wxString::Format(wxT("%s"), buffer));
	getchar();
	return 0;
}
did i do sth. wrong ?
[/size]
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: * why wxT("%s", c_type_str) print nothing ?

Post by doublemax »

Code: Select all

char buffer[80] = "Guten Tag!";
Use a char buffer.

Also, if you need it for debug output, wxLogMessage might be more convenient:

Code: Select all

char buffer[80] = "Guten Tag!";
wxLogMessage( wxT("wxlogmessage: %s"), buffer );
Use the source, Luke!
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: * why wxT("%s", c_type_str) print nothing ?

Post by whoops »


In wxWidgets 3.0.2, the fllowing code:

Code: Select all

#include <wx/wx.h>
int main()
{
	wxInitializer wx;
	if( !wx.IsOk() ) return -1;
	unsigned char buffer[80] = "Guten Tag!";
	wxLogMessage( wxT("wxLogMessage: %s"), buffer );
	wxLogMessage( wxString(buffer) );
	getchar();
	return 0;
}
print:
19:53:16: Guten Tag!
which mean that line 7 wxLogMessage( wxT("wxLogMessage: %s"), buffer ); doesn't work...
and another form wxLogMessage( wxString::Format(wxT("%s"), buffer) ); also doesn't work
and i don't know why, can you explain it to me? thanks very much :-)
[/size]
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: * why wxT("%s", c_type_str) print nothing ?

Post by doublemax »

Code: Select all

char buffer[80] = "Guten Tag!";
Like i said before, i must be a char buffer, not unsigned char. Otherwise the implicit conversion to unicode does not work.
Use the source, Luke!
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: * why wxT("%s", c_type_str) print nothing ?

Post by whoops »


oh, it's very kind of you, thanks very much. sir :D
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
Post Reply