Apr 13, 2013 at 2:23pm UTC
My problem is that there is a function I need to use from the SDL library. I have to pass a message of type const char* usually like this
function("message");
I need a way to concatenate the original message with a char* array I have set up for example
function("message"+array[1]);
I would even like to create the message then add the array element onto it but it says I can't do it since they have to be constant.
Sorry if this doesn't make sense but I have tried to make it as simple as I can, Thanks.
Apr 13, 2013 at 2:30pm UTC
Don't use char arrays unless you have to. Use strings.
When you need to pass the string to a function that takes a
const char *
, use the c_str member:
1 2 3 4 5
string array[10] = { "whatever" , "foo" , "bar" , "blah" };
string msg = "message" + array[1];
function( msg.c_str() ); // <- to "convert" to const char*
Of if you want, you can remove the 'msg' temp variable:
function( ("message" + array[1]).c_str() ); // <- legal as long as array[1] is a string
Secondly... please tell me you are not using SDL 1.2. It is horribly ancient and outdated.
Last edited on Apr 13, 2013 at 2:33pm UTC
Apr 13, 2013 at 2:37pm UTC
Ok thanks for that I will give it a try now and sadly yes I'm planning on making space invaders since I'm pretty new to the gui stuff, what would you recommend I use instead? OpenGL?
Apr 13, 2013 at 3:39pm UTC
I like SFML.
But There's a more modern version of SDL ("SDL HG" or "SDL 2.0") which supposedly fixes the problems with SDL 1.2.
Anyway... SDL 1.2 will work... it just gets crap performance, is severely limited/crippled, and uses extremely outdated drawing concepts.