ExampleCString str;
int nAsked = 5;
int nAgree = 4;str.FormatMessage(_T("%1!d! of %2!d! developers agree: Hockey is %3%!"), 
   nAgree, nAsked, _T("Best"));
ASSERT(str == _T("4 of 5 developers agree: Hockey is Best!"));上面这小段代码是摘至MSDN里的,有一点我不明白,就是为什么会是
%1!%d!
%2!%d!
%3!%!
呢?加上!这个是什么意思呢?以前看格式化字符串时,也不是这样的啊

解决方案 »

  1.   

    嘿嘿,FormatMessage这不是普通的格式化吧
      

  2.   

    这个问题我也不是很清楚,不过你可以看看msdn.如下。
    CString::FormatMessage
    void FormatMessage( LPCTSTR lpszFormat, ... );void FormatMessage( UINT nFormatID, ... );ParameterslpszFormatPoints to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time functionprintf-style format strings, except it allows for the parameters to be inserted in an arbitrary order.nFormatIDThe string resource identifier that contains the unformatted message text.ResCall this member function to format a message string. The function requires a message definition as input. The message definition is determined by lpszFormat or from the string resource identified by nFormatID. The function copies the formatted message text to the CString, processing any embedded insert sequences if requested.Each insert must have a corresponding parameter following the lpszFormat or nFormatID parameter. Within the message text, several escape sequences are supported for dynamically formatting the message. For a description of these escape sequences and their meanings, see the Windows::FormatMessage function in the Win32 SDK Programmer’s Reference.
      

  3.   

    晕死哦
    跟我上面的合起来不就是下面的吗CString::FormatMessage
    void FormatMessage( LPCTSTR lpszFormat, ... );void FormatMessage( UINT nFormatID, ... );ParameterslpszFormatPoints to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time functionprintf-style format strings, except it allows for the parameters to be inserted in an arbitrary order.nFormatIDThe string resource identifier that contains the unformatted message text.ResCall this member function to format a message string. The function requires a message definition as input. The message definition is determined by lpszFormat or from the string resource identified by nFormatID. The function copies the formatted message text to the CString, processing any embedded insert sequences if requested.Each insert must have a corresponding parameter following the lpszFormat or nFormatID parameter. Within the message text, several escape sequences are supported for dynamically formatting the message. For a description of these escape sequences and their meanings, see the Windows::FormatMessage function in the Win32 SDK Programmer’s Reference.ExampleCString str;
    int nAsked = 5;
    int nAgree = 4;str.FormatMessage(_T("%1!d! of %2!d! developers agree: Hockey is %3%!"), 
       nAgree, nAsked, _T("Best"));
    ASSERT(str == _T("4 of 5 developers agree: Hockey is Best!"));
    不过好像找不到  Windows::FormatMessage 函数啊