
A Formatting String Function 原文:http://flounder.com/tostring.htm
CString ToString(LPCTSTR fmt, ...); |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include "stdafx.h"
#include "ToString.h" /**************************************************************************** * ToString * Inputs: * LPCTSTR fmt: Format code * ...: Values to format * Result: CString * The values formatted to a string according to the format string ****************************************************************************/ CString ToString(LPCTSTR fmt, ...) CString s; va_end(args); CString ToString(UINT fmtid, ...) CString fmt; CString s; va_end(args); |
使用:
CString s = ToString(_T("value = %d"), value);
SomeFunction(ToString(_T("(%d, %d)"), x, y);