@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*'
extending the window caption
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:
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement