Created
July 25, 2014 11:03
-
-
Save alepez/f837571c9dcf50ff4541 to your computer and use it in GitHub Desktop.
Create a string as printf do
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
#ifndef FORMAT_H_ | |
#define FORMAT_H_ | |
#include <string> | |
#include <cstdarg> | |
#include <cstdio> | |
class Format: public std::string { | |
public: | |
inline Format(const char* format, ...) { | |
va_list args; | |
va_start(args, format); | |
size_t const bufferSize = ::vsnprintf(0, 0, format, args) + 1; | |
this->resize(bufferSize); | |
va_end(args); | |
va_start(args, format); | |
::vsnprintf(&((*this)[0]), bufferSize, format, args); | |
va_end(args); | |
} | |
}; | |
#endif /*FORMAT_H_*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment