如何连接文件路径?

How can I concatenate file path?

我只需要连接一个文件路径,在 C++ 中使用库 SDL Mixer 2.0:

像这样:

#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)

Mix_LoadWAV 收到 char *file 因此您需要将 std::string 转换为 char*

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