#include#include //字符串格式化 template std::string StrFormat(const char* format, Args... args) { int length = std::snprintf(nullptr, 0, format, args...); if (length <= 0) { return ""; } char* buf = new char[length + 1]; std::snprintf(buf, length + 1, format, args...); std::string str(buf); delete[] buf; return std::move(str); } int main() { std::string t = StrFormat("this is a %s and %d", "hello", 1); std::cout << t << std::endl; }



