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.
whoops
Earned a small fee
Posts: 23 Joined: Sat Jun 27, 2015 5:53 am
Location: China
Post
by whoops » Thu Aug 13, 2015 4:41 am
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 ]
doublemax
Moderator
Posts: 19160 Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2
Post
by doublemax » Thu Aug 13, 2015 8:08 am
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!
whoops
Earned a small fee
Posts: 23 Joined: Sat Jun 27, 2015 5:53 am
Location: China
Post
by whoops » Thu Aug 13, 2015 12:02 pm
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 ]
doublemax
Moderator
Posts: 19160 Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2
Post
by doublemax » Thu Aug 13, 2015 12:19 pm
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!
whoops
Earned a small fee
Posts: 23 Joined: Sat Jun 27, 2015 5:53 am
Location: China
Post
by whoops » Thu Aug 13, 2015 12:37 pm
oh, it's very kind of you, thanks very much. sir
Things being equal, the simplest explanation tends to be the right.
[ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]