Created
May 13, 2014 08:37
-
-
Save psycharo-zz/d339d3787645c253e168 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| string string_format(const string fmt, ...) | |
| { | |
| int size = 512; | |
| std::string str; | |
| va_list ap; | |
| while (1) { | |
| str.resize(size); | |
| va_start(ap, fmt); | |
| int n = vsnprintf((char *)str.c_str(), size, fmt.c_str(), ap); | |
| va_end(ap); | |
| if (n > -1 && n < size) { | |
| str.resize(n); | |
| return str; | |
| } | |
| if (n > -1) | |
| size = n + 1; | |
| else | |
| size *= 2; | |
| } | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment