STL::STRING格式化字符串

void __inline __cdecl StdFormatA(std::string &buf, const char *format, ...)
{
	va_list vl;
	long nCount;
	char *lpBuffer;

	va_start(vl, format);
	nCount = _vscprintf(format, vl) + 1;
	lpBuffer = new char[nCount];
	_vsnprintf_s(lpBuffer, nCount, _TRUNCATE, format, vl);
	buf = std::string(lpBuffer);
	delete[] lpBuffer;
	va_end(vl);
}

void __inline __cdecl StdFormatW(std::wstring &buf, const wchar_t *format, ...)
{
	va_list vl;
	long nCount;
	wchar_t *lpBuffer;

	va_start(vl, format);
	nCount = _vscwprintf(format, vl) + 1;
	lpBuffer = new wchar_t[nCount];
	_vsnwprintf_s(lpBuffer, nCount, _TRUNCATE, format, vl);
	buf = std::wstring(lpBuffer);
	delete[] lpBuffer;
	va_end(vl);
}

你可能感兴趣的:(STL::STRING格式化字符串)