wxString concatenation operator weirdness

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
dot-borg
In need of some credit
In need of some credit
Posts: 6
Joined: Fri Jul 18, 2008 6:28 pm

wxString concatenation operator weirdness

Post by dot-borg »

Hi,

I'm having an issue with the wxString << operator, but only in wxMSW (unicode). The following code produces the string "35":

Code: Select all

wxString text;
int value = 35;
text << wxString::Format(_T("%d"), value);
However, this produces "%":

Code: Select all

wxString text;
int value = 35;
text << value;
I've looked at the wxString code and it appears that the << operator is doing exactly what I'm doing in the first case. Could this have something to do with unicode? Did I build the library incorrectly (I used "mingw32-make.exe -f makefile.gcc USE_XRC=1 SHARED=0 MONOLITHIC=1 BUILD=debug UNICODE=1")?
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

I'm not sure, but you're giving Format an INT while it's expecting a double. That might be the problem.
dot-borg
In need of some credit
In need of some credit
Posts: 6
Joined: Fri Jul 18, 2008 6:28 pm

Post by dot-borg »

Where is it expecting a double?
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

the %d tells format that it's looking for a double/float i believe. Try changing the int definition to a double and then give format a precision of 1(one).

also, you could check out this thread:
http://forums.wxwidgets.org/viewtopic.p ... +precision

is there a necessary reason to use the << operator and not the .(dot) operator?
dot-borg
In need of some credit
In need of some credit
Posts: 6
Joined: Fri Jul 18, 2008 6:28 pm

Post by dot-borg »

SteveDowd wrote:the %d tells format that it's looking for a double/float i believe. Try changing the int definition to a double and then give format a precision of 1(one).

also, you could check out this thread:
http://forums.wxwidgets.org/viewtopic.p ... +precision
The "%d" format specifier is for signed decimal integer and has been since the dawn of the standard C library.

[edit] Also, the first example I gave is the one that works.
SteveDowd wrote:is there a necessary reason to use the << operator and not the .(dot) operator?
There's no reason (other than convenience) to use the << operator over the Format static member function. It just makes me think something was not built correctly which calls into question other areas of the framework which may experience similar issues.
SteveDowd
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Sep 28, 2005 3:16 pm
Location: Florida

Post by SteveDowd »

my mistake, i was thinking that they had a different format character for each individual type.
Post Reply