如何组合这些字符串以输入PlaySound方法

时间:2014-05-13 00:16:36

标签: c++ string

我有这个代码在最后没有.exe文件的情况下获取我的项目路径:

string ExePath() {
    char buffer[MAX_PATH];
    GetModuleFileName( NULL, buffer, MAX_PATH );
    string::size_type pos = string( buffer ).find_last_of( "\\/" );
    return string( buffer ).substr( 0, pos);
}

当我使用这个ExePath()方法时,我得到c:/blah/blah/Debug,我想要播放的.wav文件位于该文件夹中。

所以我需要致电PlaySound(/* path to wav file */, NULL, SND_ASYNC);,但我不能简单地将ExePath()MySound.wav结合起来,我会收到错误。

我该怎么做?

我说:PlaySound(ExePath().c_str() + "MySound.wav", NULL, SND_ASYNC);但我收到错误,说MySound.wav部分说错误:表达式必须包含整数或无范围的枚举类型

1 个答案:

答案 0 :(得分:1)

我解决了。我用了这段代码:

PlaySound(ExePath().append("MySound.wav").c_str(), NULL, SND_ASYNC);