Page 1 of 1

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

Posted: Thu Aug 13, 2015 4:41 am
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]

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

Posted: Thu Aug 13, 2015 8:08 am
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 );

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

Posted: Thu Aug 13, 2015 12:02 pm
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]

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

Posted: Thu Aug 13, 2015 12:19 pm
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.

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

Posted: Thu Aug 13, 2015 12:37 pm
by whoops

oh, it's very kind of you, thanks very much. sir :D