首页 > 其他 > 详细

std::string stringf(const char* format, ...)

时间:2015-01-19 10:42:27      阅读:257      评论:0      收藏:0      [点我收藏+]

std::string stringf(const char* format, ...)
{
va_list arg_list;

va_start(arg_list, format);

// SUSv2 version doesn‘t work for buf NULL/size 0, so try printing
// into a small buffer that avoids the double-rendering and alloca path too...
char short_buf[256];
const size_t needed = vsnprintf(short_buf, sizeof short_buf,
format, arg_list) + 1;
if (needed <= sizeof short_buf)
return short_buf;

// need more space...
char* p = static_cast<char*>(alloca(needed));
vsnprintf(p, needed, format, arg_list);
return p;
}

std::string stringf(const char* format, ...)

原文:http://www.cnblogs.com/ytjjyy/p/4233046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!