Created
February 24, 2012 06:12
-
-
Save Surye/1898257 to your computer and use it in GitHub Desktop.
vsprintf issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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