whats the best way of creating a ‘const char*’ using available variables? For example, a function requires a const char* as a parameter to locate a file i.e. “invader1.png”. If I have 5 different invader images, how can I iterate from 1:5 so “Invader1.png”..”Invader2.png..etc etc
so i want “invader” + %d + “.png”
i tried sprintf and casting but to no avail.
I hope my description makes sense, thanks
update with code:
for (int y=0; y<250; y+=50){
stringstream ss;
ss << "invader" << (y/50) << ".png";
const char* rr = ss.str().c_str();
printf("%s", rr);
for (int x=0; x<550;x+=50){
Invader inv(rr, x+50, y+550, 15, 15, 1, false, (y/50 + 50));
invaders[i] = inv;
i++;
}
}
Use
std::stringstream. Something like this: