C++中传递可变参数

std::string & getFormattedStr(std::string &strFormatted, const char *strFormat, va_list arglist)
{
	const int MAX_FORMATTED_STR_LEN = 2048;
	char strResult[MAX_FORMATTED_STR_LEN] = { 0 };
	vsprintf_s(strResult, strFormat, arglist);
	strFormatted = strResult;
	return strFormatted;
}


void logToStd(const char *strFormat, ...)
{
	std::string strLog;
	va_list arglist;
	va_start(arglist, strFormat);
	strLog = getFormattedStr(strLog, strFormat, arglist);
	va_end(arglist);
	std::cout << strLog << std::endl;
}

你可能感兴趣的:(C/C++)