Create string formatted in C (MFC)

How can I create formatted string in VC++ (Visual Studio 2010)?

I can create in this way:

CString str;
str.Format("%d bla %d", 10, 20);

but I want something like:

CString str = MACRO_OR_FUNCTION("%d bla %d", 10, 20);

I know how to implement it, but I preferer to use if it was implemented by MFC.

My question is: Isthis macro or function in MFC or some stand lib? If has it in MFC for example I wont implement my version. I will prefer to use it.

Upvotes: 4

Views: 2347

Answers (1)

oldmonk
oldmonk

Reputation: 739

You need declare a function.

CString fn_s_Format( LPCTSTR pctszFormat, ... )
{
    CString s ;

    va_list argList;
    va_start( argList, pctszFormat );
    s.FormatV( pctszFormat, argList );
    va_end( argList );

    return s ;
}

Upvotes: 4

Related Questions