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

一个格式化字符串的函数ToString的更多相关文章

  1. 飘逸的python - 增强的格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  2. Python 的格式化字符串format函数

    阅读mattkang在csdn中的博客<飘逸的python - 增强的格式化字符串format函数>所做笔记 自从python2.6开始,新增了一种格式化字符串的函数str.format( ...

  3. 格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  4. (转)飘逸的python - 增强的格式化字符串format函数

    原文:https://blog.csdn.net/handsomekang/article/details/9183303 Python字符串格式化--format()方法-----https://b ...

  5. 增强的格式化字符串format函数

    http://blog.csdn.net/handsomekang/article/details/9183303 自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓 ...

  6. 【Python开发】增强的格式化字符串format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...

  7. 面试题之java 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 要求不能出现截半的情况

    题目:10. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串. 但是要保证汉字不被截半个,如"我ABC"4,应该截为"我AB",输 ...

  8. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是“我ABC+汉的半个”。

    一.需要分析 1.输入为一个字符串和字节数,输出为按字节截取的字符串--->按照字节[byte]截取操作字符串,先将String转换成byte类型 2.汉字不可以截半--->汉字截半的话对 ...

  9. java算法面试题:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串,但要保证汉字不被截取半个, 如“我ABC”,4,应该截取“我AB”,输入“我ABC汉DEF”,6,应该输出“我ABC”,而不是“我ABC+汉的半个”。

    package com.swift; import java.util.Scanner; public class Hanzi_jiequ { public static void main(Stri ...

随机推荐

  1. OpenCV求取轮廓线

    // Threshold.cpp : Defines the entry point for the console application. // #include "stdafx.h&q ...

  2. mysql.ini 配置

    #记录所有sql语句 log=E:/mysqllog/mysql.log #记录数据库启动关闭信息,以及运行过程中产生的错误信息 log-error=E:/mysqllog/myerror.log # ...

  3. git——分布式版本控制系统

    Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件 ...

  4. Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50518, now running 50641. Please use mysql_upgrade to fix this error.

    出现问题: Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50518, now runn ...

  5. C# 编写Windows服务在VS中调试的步骤

    1.以管理员身份运行cmd 2.安装windows服务 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319(InstallUtil.exe的路径,注意In ...

  6. FFmpeg + SDL2 实现的视频播放器「视音频同步」

    文章转自:http://blog.csdn.net/i_scream_/article/details/52760033 日期:2016.10.8 作者:isshe github:github.com ...

  7. 《转》CentOS7 安装MongoDB 3.0server (3.0的优势)

    1.下载&安装 MongoDB 3.0 正式版本号公布!这标志着 MongoDB 数据库进入了一个全新的发展阶段,提供强大.灵活并且易于管理的数据库管理系统.MongoDB宣称.3.0新版本号 ...

  8. RFID编码

    信号编码系统包括信源编码和信道编码两大类,器作用是把要传输的信息尽可能的与传输信道相匹配,并提供对信息的某种保护以防止信息受到干扰.信源编码与信源译码的目的是提高信息传输的有效性以及完成模数转换等:信 ...

  9. ubuntu下查找jdk安装位置

    which javac 返回/usr/bin/javac file /usr/bin/javac 返回/usr/bin/javac: symbolic link to `/etc/alternativ ...

  10. MySQL主从复制状态及数据一致性监测工具

    转: https://blog.csdn.net/m0_37814112/article/details/80914713