#include <string> #include <stdarg.h> #include <windows.h> using namespace std; std::string varFormatString( const char* fmt, ... ) { const int SIZE=500; char strLog[SIZE+1]; strLog[SIZE] = NULL; va_list list; va_start(list, fmt); _vsnprintf(strLog, SIZE, fmt, list); va_end(list); return strLog; } int main() { printf("%s",varFormatString("test: %d + %d = %d\n",1,2,3).c_str()); return 0; }
C++ 变参va_list 示例
最新推荐文章于 2024-07-15 11:32:00 发布
本文介绍了一个使用 C++ 实现的可变参数列表函数 varFormatString 的示例,该函数模仿了 C 语言中 vsnprintf 的行为,并在 main 函数中进行了测试。
743

被折叠的 条评论
为什么被折叠?



