Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 575
Wanderley Guimarães Avatar asked Oct 31 '25 00:10

Wanderley Guimarães


1 Answers

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 ;
}
like image 51
oldmonk Avatar answered Nov 02 '25 13:11

oldmonk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!