I'm a noob trying to learn c++ and allegro and was following a tutorial which is how I came up with this code. My issue is at line:
"textout_centre_ex(screen, font1, Draw.c_str(), scrW / 2, scrH / 2, eBlue, -1);"
When it comes to 'Draw.c_str()' I get Error: argument of type "const char*" is incompatible with parameter of type "char*".
If I try and build I get "error C2664: 'void textout_centre_ex(BITMAP *,FONT *,char *,int,int,int,int)' : cannot convert argument 3 from 'const char *' to 'char *'"
How can I resolve this?
// Set variables
int counter = 0;
std::string Word = "SuperAwesomeTrivia";
std::string Draw = "";
FONT *font1 = load_font("font1.pcx", NULL, NULL);
while (!closeWindow){
// Update
Draw += Word[counter];
counter++;
if (counter > Word.length() - 1)
{
closeWindow = true;
}
// Draw
textout_centre_ex(screen, font1, Draw.c_str(), scrW / 2, scrH / 2, eBlue, -1);
if (!closeWindow)
rest(200);
else
rest(2000);
clear_bitmap(screen);
}
destroy_font(font1);
allegro_exit();
return 0;
const char*
, not achar*
. And it makes sense since the function shouldn't modify the string. – JackAL_CONST
asconst
only when compiling with GCC. (non-GCC definition, GCC-definition) – emlaiconst_cast
is the way to go but AL_CONST rationale seems quite obsolete since it refers to compiler which doesn't supportconst
, there shouldn't be many nowadays. We don't know the OP compiler but I guess it could be safe to compile Allegro withAL_CONST const
– Jack