Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdarg>
- #include <iostream>
- #include <string>
- #ifdef __GNUC__
- # if defined _WIN32 && !defined __USE_MINGW_ANSI_STDIO
- __attribute__((__format__ (ms_printf, 1, 2)))
- # else
- __attribute__((__format__ (printf, 1, 2)))
- # endif
- #endif
- std::string StringFromFormat(const char *format, ...)
- {
- std::va_list args;
- va_start(args, format);
- std::size_t num = static_cast<std::size_t>(vsnprintf(NULL, 0, format, args));
- std::string result(num, '\0');
- vsprintf(&result[0], format, args);
- va_end(args);
- return result;
- }
- int main()
- {
- using namespace std;
- cout << StringFromFormat("%d+%d=%d23423423423423sdfgsdfgsdfgsdfg42342342343434234", 1, 2, 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement