Click to See Complete Forum and Search --> : Changing the window title


Timb
April 27th, 2008, 10:32 AM
Hey.

Basically im trying to update the window title for my program.

At the moment im using setWindowTitle to do this, but I can't figure out how to include an int variable to display properly.

I have an integer for 'lives' and setting the title to something like "setWindowTitle("Lives: " + lives); produces strange errors.

Anyone able to help?

Hermit
April 27th, 2008, 11:08 AM
You can't add an integer to a string in C++ (assuming you don't overload operator+ for that purpose). Use stringstreams:

#include <sstream>

// ...

std::ostringstream oss;
oss << "Lives: " << lives;
setWindowTitle(oss.str().c_str()); // Assuming setWindowTitle takes a C-style string

Timb
April 27th, 2008, 11:17 AM
Thanks heaps, that really helped