sprintf expects two parameters, with additional ones expected to match format specifiers used in the second parameter. The format specifiers follow the ones used for the printf function here http://www.cplusplus.com/reference/cstdio/printf/
Is the -r supposed to be interpreted as a format specifier?
You could build a string with the C++ string instead of c-style strings. I'm just outputting the combined string instead of running it, but I think this is what you're trying to do?