MFC/ATL - 文字列フォーマット

型安全じゃないとか言っていても、それでも便利な文字列フォーマット関数


なんでCString::Formatがstaticメンバじゃないんだろう?

inline CString FormatString(LPCTSTR szFormat, ...)
{
    CString strFmt;

    va_list argList;
    va_start(argList, szFormat);
    strFmt.FormatV(szFormat, argList);
    return strFmt;
}
CString str = FormatString(_T("abc%d"), 314);

boost::formatもこんな感じで書ければいいのになー
(今のboost::formatの方が型安全なんだろうけど、好みの問題)

string  astr = format("%1", 314);
wstring wstr = wformat(L"%1", 314);