Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mixing Strings and Ints 1

Status
Not open for further replies.

ASingerMustDie

Programmer
Feb 1, 2001
17
GB
Hi All :)

Sorry to barge in here with yet another question...but this one surely IS trivial this time :)

Having said that though, everything I expected to work either didn't or crashed.

The problem is this, I was two variables displayed inside a static text control, i.e:

var1 = 12; //could be anything
var2 = 35; //ditto

staticText.setWindowText("var 1: " + var1 + "var2: " + var2);

I am surely overlooking something obvious...I really do feel rusty. Thanks for any aid, you have been most helpgul and forthcoming in the (non-too-distant) past :)

Regards.
 
Well i'm no expert but usually c++ doesn't like plus signs like that. Try using commas instead.

staticText.setWindowText("var 1:",var1," var2:",var2);

I don't know if that will work but its worth a try.
 
I think that the CString::Format function might be just what you need. For instance, if var1 and var2 are both signed integers, this code should work:

CString sWindowText;
sWindowText.Format( "var1: %d var2: %d", var1, var2 );
staticText.SetWindowText( sWindowText );

If var1 and var2 were declared as "unsigned int", then just replace both occurrences of %d with %u in the Format function call.

A good place to learn more about CString::Format is

 
Thanks Keith, I had tried the Format method but must have misinterpreted its usage and ended up using %s instead of %d, which crashed the computer.

All works fine now, thanks much. And to MaxDaddy :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top