c++audiomp3volumemcisendstring

C++ mciSendString setaudio error


I have this function here; volume is set to 500, and the filename string is set to "test.mp3".

void Volume(int volume, std::string filename)
        {
        std::string szCommand = "setaudio \"" + filename + "\" volume to " + volume;
        mciSendString(szCommand.c_str(), NULL, 0, 0);
    }

It is giving me the error;

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'|

I have no idea why because the following function below works perfectly when loading the .mp3 file

void Load(std::string filename)
    {
        std::string szCommand = "open \"" + filename + "\" type mpegvideo alias " + filename;
        mciSendString(szCommand.c_str(), NULL, 0, 0);
    }

I am confused why it doesn't work. What is wrong with setaudio not accepting the filename? I searched everywhere and there's no answer, not even on MSDN.


Solution

  • This is not working because volume is an integer and not a string. You need to convert the integer to a string. Depending on your compiler, you should be able to use std::to_string to convert from int to string.