Advertisement

extending the window caption

Started by April 07, 2005 06:56 AM
12 comments, last by bearS 19 years, 10 months ago
@taby -u have something serious interesting in ur snippet
that part of convering true/false to int before attepting to write
however the snippet creates an error
invalid conversion from `const char*' to `char*'
regards a.
sprintf( buffer, "%s", boolean ? "true" : "false" );
Advertisement
The reason you are receiving a "cannot convert const char* to char*" error is because the first parameter of CreateGLWindow requires that the string passed in to be non-const.

This is an extremely horrible design flaw committed by the creators of that library, but you can work around it by using the const_cast cast operator:

#define DEFAULT_WINDOW_TITLE "My Application"#include <sstream>using std::ostringstream;#include <ios>using std::boolalpha;...ostringstream title;// remove the call to boolalpha to format the bool as 1 or 0 instead of "true" or "false"title << DEFAULT_WINDOW_TITLE << " state is now: " << boolalpha << boolean_var;if(!CreateGLWindow(const_cast<char *>(title.str().c_str()), 640, 480, 16, fullscreen)){    ...}...


P.S. The reason why you were experiencing incompatibilities between bool and sprintf is because sprintf is a C library function, and bool is a C++ type. Therefore, there is no formatting specification token for bool. Like posted above, you have to work around this by either using the %d token to print it as an integer, or the %s / ternary operator to print it as a string (which by the way, was quite an ingenious snippet of code Illco).
@taby & illco
Lovely- that creates the wanted concat of strings in the gl window
(-the bool is not updated though but thats an other story:)
regards a.

This topic is closed to new replies.

Advertisement