不定长参数格式化输出(支持中文字符)

不定长参数格式化输出(支持中文字符)

#include <iostream>
#include < string>
void myformat( const  char *fmt,  )
{
va_list ap;
va_start(ap, fmt);
wchar_t buf[2048];
vswprintf(buf,fmt,ap);
va_end(ap);
std::wcout.imbue(std::locale("chs"));
std::wcout<<buf<<std::endl;
}
如果要返回值:
#include <iostream>
#include < string>
std::wstring myformat( const  char *fmt,  )
{
va_list ap;
va_start(ap, fmt);
wchar_t buf[2048];
vswprintf(buf,fmt,ap);
va_end(ap);
std::wstring str = std::wstring(buf);
return str;
}

你可能感兴趣的:(不定长参数格式化输出(支持中文字符))