Skip to content

Instantly share code, notes, and snippets.

@Surye
Created February 24, 2012 06:12
Show Gist options
  • Save Surye/1898257 to your computer and use it in GitHub Desktop.
Save Surye/1898257 to your computer and use it in GitHub Desktop.
vsprintf issue
#include <cstdarg>
#include <string>
#include <iostream>
void debug(std::string c_fmt, ...);
int main() {
debug("Testing: %d", 12345); // Testing: -858993460
}
void debug(std::string fmt, ...)
{
char buf[1024] = {0};
const char* c_fmt = fmt.c_str();
va_list ap;
va_start(ap, c_fmt);
vsprintf(buf, c_fmt, ap);
va_end(ap);
std::cout << buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment