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

  • 相关阅读:
    从当前url替换获得新的url
    访问者模式
    备忘录模式
    make makefile cmake qmake 区别
    qt编译过程
    tensorflow前处理
    tesorflow操作
    tensorflow的object_detection安装
    tensorflow 编译与训练
    tensorflow后处理
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7018212.html
Copyright © 2011-2022 走看看