zoukankan      html  css  js  c++  java
  • 一个格式化字符串的函数ToString

      A Formatting String Function  原文:http://flounder.com/tostring.htm

    CString ToString(LPCTSTR fmt, ...);
    CString ToString(UINT fmtid, ...);
     C++ Code 
    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, ...) 

        va_list args; 
        va_start(args,fmt); 

        CString s; 
        s.FormatV(fmt, args); 

        va_end(args); 
        
    return s; 
    // ToString 
       
    /**************************************************************************** 
    *                         ToString 
    * Inputs: 
    *     UINT fmt: String ID of formatting string 
    *     ...: parameters to formatting string 
    * Result: CString 
    *     The result of the formatting 
    ****************************************************************************/
     

    CString ToString(UINT fmtid, ...) 

        va_list args; 
        va_start(args,fmtid); 

        CString fmt; 
        fmt.LoadString(fmtid); 

        CString s; 
        s.FormatV(fmt, args); 

        va_end(args); 
        
    return s; 
    // ToString   

      使用:
      CString s = ToString(_T("value = %d"), value);
      SomeFunction(ToString(_T("(%d, %d)"), x, y);

  • 相关阅读:
    SQL2008-显示表大小行数
    SQL2008-备份SQL数据库的语句
    SQL2008-截取字段函数
    SQL2008-字符转数字CAST和CONVERT
    SQL2008-查询库中是否存在某表
    SQLServer 2000个人版下载
    SQL2008-不同数据库之间的触发器
    SQL2008--行号的得到
    Microsoft Visual Stduio 2005 Ent安装报错解决方法
    zlib快速编译脚本
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7018212.html
Copyright © 2011-2022 走看看