C plus plus sprintf用法
sprintf
int sprintf ( char * str, const char * format, ... );
Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in
the buffer pointed by str.
The size of the buffer should be large enough to contain the entire resulting string (see snprintf for a safer version).
A terminating null character is automatically appended after the content.
After the format parameter, the function expects at least as many additional arguments as needed for format.
Parameters
- str
- Pointer to a buffer where the resulting C-string is stored.
The buffer should be large enough to contain the resulting string. - format
- C string that contains a format string that follows the same specifications as format in printf (see printf for
details). - ... (additional arguments)
- Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage
location, for n).
There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.
Return Value
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.
On failure, a negative number is returned.
中文版:
函数功能:把格式化的数据写入某个字符串
函数原型:int sprintf( char *buffer, const char *format [, argument] … );
返回值:字符串长度(strlen)
例子:
char* who = "I";
char* whom = "CSDN";
sprintf(s, "%s love %s.", who, whom); //产生:"I love CSDN. " 这字符串写到s中
sprintf(s, "%10.3f", 3.1415626); //产生:" 3.142"
C plus plus sprintf用法的更多相关文章
- C++小知识之sprintf用法
sprintf 字串格式化命令,主要功能是把格式化的数据写入某个字符串中.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内存访问错误,但好在由sprintf ...
- sprintf 用法
字符串格式化命令,主要功能是把格式化的数据写入某个字符串中 试试下面的代码就知道了 #include<cstdio> #include<cstdlib> using names ...
- php sprintf用法
sprintf用来格式化字符串 说明 string sprintf ( string $format [, mixed $args [, mixed $... ]] 参数 $format 可能的格式值 ...
- sscanf,sprintf用法
#include<string.h> #include<stdio.h> int main() { ],sztime1[],sztime2[]; sscanf("12 ...
- sprintf用法
函数简介 函数功能:把格式化的数据写入某个字符串 头文件:stdio.h 函数原型:int sprintf( char *buffer, const char *format [, argument] ...
- c++ sprintf() 用法
1. char boxData[100]; fi.mWidth = 1.0, fi.mCenter_x= 2.1, fi.mCenter_y=1.1; sprintf(boxData, " ...
- WordPress翻译中 __()、_e()、_x、_ex 和 _n 的用法及区别
编译函数 WordPress使用了下面几个函数来方便语言本地化. __() _e() _x() _ex() _n() 以上所列的函数是用来包含所需翻译的字符串的,根据字符串的不同参数和输出类型,需要使 ...
- sprintf()详细介绍
sprintf 编辑词条 编辑词条 --> 字串格式化命令,主要功能是把格式化的数据写入某个字符串中.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内 ...
- sprintf格式化字符串安全问题
先看sprintf用法: 定义和用法 sprintf() 函数把格式化的字符串写入变量中. arg1.arg2.++ 参数将被插入到主字符串中的百分号(%)符号处.该函数是逐步执行的.在第一个 % 符 ...
随机推荐
- 【Todo】秒杀系统 & 乐观锁 & Nginx反向代理
http://www.csdn.net/article/2014-11-28/2822858 1. 单点帐号验证,不用读,而是用写入,Redis,看是否加watch 2. 抢宝的最终购买冲突.包装称“ ...
- Working with Validators and Messages in AngularJS
原文:http://odetocode.com/blogs/scott/archive/2014/10/16/working-with-validators-and-messages-in-angul ...
- BZOJ 1091([SCOI2003]分割多边形-分割直线)
1091: [SCOI2003]分割多边形 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 223 Solved: 82 [Submit][id=10 ...
- java克隆对象clone()的使用方法和作用
转自:997.html">http://www.okrs.cn/blog/news/?997.html 内容摘要 若需改动一个对象,同一时候不想改变调用者的对象.就要制作该对象的一个本 ...
- 将C++的标识符转成OC的标识符
3.将C++的标识符转成OC的标识符 C++的标识符和OC一样由数字字母下划线组成.打头的不是数字.当标识符超过一个单词, C++採用全字母小写.单词间用下划线连接的书写规范,如: bei_jing ...
- Hadoop之中的一个:Hadoop的安装部署
说到Hadoop不得不说云计算了,我这里大概说说云计算的概念,事实上百度百科里都有,我仅仅是copy过来,好让我的这篇hadoop博客内容不显得那么单调.骨感.云计算近期今年炒的特别火,我也是个刚開始 ...
- TCP协议,UDP协议
帅爆太阳的男人 1,TCP协议 回环地址:127.0.0.1(所有电脑都这一个默认回环地址)每个计算机都有这么一个本机地址只能被本机识别,不会被其他机器识别(因为你用这个地址传内容他就传不出去) TC ...
- 不常见使用的css
flex和white-space等属性 1.flex属性让所有弹性盒模型对象的子元素都有相同的长度,忽略它们内部的内容.style={{flex:5}},该元素占父元素的六分之五. 2. white- ...
- bzoj1560: [JSOI2009]火星藏宝图
考虑到一个性质,A到B的距离一定不小于A到C再到B的距离,因为能够到达这三个点不可能构成锐角三角形 对于当前点的更新只需要找那些无法经过其它点再到当前点的点,相当于是一个y坐标单调减的上凸包,随便维护 ...
- 工作笔记——sqlserver引号的运用
一. sqlserver引号问题:因为要使用远程连接,所以sql语句要用单引号括起来 SELECT * FROM OPENQUERY ([192.168.***.***] ,'select * fro ...