我这里有这个功能; 音量设置为 500,文件名字符串设置为“test.mp3”。
void Volume(int volume, std::string filename)
{
std::string szCommand = "setaudio \"" + filename + "\" volume to " + volume;
mciSendString(szCommand.c_str(), NULL, 0, 0);
}
它给我错误;
no match for 'operator+' in 'std::operator+(std::basic_string<_CharT, _Traits, _Alloc>&&, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>](((const char*)"\" volume to ")) + volume'|
我不知道为什么,因为下面的函数在加载 .mp3 文件时完美运行
void Load(std::string filename)
{
std::string szCommand = "open \"" + filename + "\" type mpegvideo alias " + filename;
mciSendString(szCommand.c_str(), NULL, 0, 0);
}
我很困惑为什么它不起作用。 setaudio 不接受文件名有什么问题?我到处搜索,但没有答案,甚至在 MSDN 上也没有。
最佳答案
这不起作用,因为 volume
是整数而不是字符串。您需要将整数转换为字符串。根据您的编译器,您应该能够使用 std::to_string从 int 转换为字符串。
关于C++ mciSendString 设置音频错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19647872/