【问题标题】:How can I concatenate file path?如何连接文件路径?
【发布时间】:2019-10-02 01:53:38
【问题描述】:

我只需要在 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)

【问题讨论】:

  • myColor in Mix_LoadWAV() 不应该用引号引起来,因为你试图传递一个变量,而不是一个字符串
  • 哦,我也试过了……我打错字了

标签: c++ file char concatenation sdl


【解决方案1】:

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

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

【讨论】:

  • 伙计,非常感谢!!!我和其他人一起成功了,但这很简单而且效果很好!!!!非常感谢!!!
猜你喜欢
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-10
  • 1970-01-01
  • 2021-02-01
  • 1970-01-01
相关资源
最近更新 更多