Search code examples
c++filecharconcatenationsdl

How can I concatenate file path?


I need only concatenate a file path, in C++ using library SDL Mixer 2.0:

something like this:

#include<SDL2/SDL_mixer.h>

string myColor = "red";

sound = Mix_LoadWAV("D:\\car"+myColor+".wav"); //or this
sound = Mix_LoadWAV("D:\\car"+"red"+".wav");
// is generate a error:

#define Mix_LoadWAV(file)

Solution

  • Mix_LoadWAV receives a char *file so you'll need to convert from std::string to char*

    sound = Mix_LoadWAV(("D:\\car" + myColor + ".wav").c_str());