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);

  • 相关阅读:
    CSS背景background、backgroundposition使用详解
    为何img、input等内联元素可以设置宽、高
    各种Js封装
    CSS布局奇淫技巧之各种居中
    document.compatMode属性
    jquery的each()详细介绍
    jQuery所支持的css样式
    js,jQuery获取html5的data*属性
    PHP中MVC的编程思想浅谈
    php读取xml的神器
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7018212.html
Copyright © 2011-2022 走看看