C++官网参考链接:https://cplusplus.com/reference/cstdio/vsprintf/

函数 
<cstdio>
vsprintf
int vsprintf (char * s, const char * format, va_list arg );
将格式化数据从可变实参列表写入字符串
如果在printf上使用format,将打印用相同的文本组成的一个字符串,但这里使用arg标识的可变实参列表中的元素,而不是其他函数实参,并将结果内容作为C字符串存储在s指向的缓冲区中。
在内部,该函数从arg标识的列表中获取实参,就像对它使用了va_arg一样,因此arg的状态很可能被调用改变。
在任何情况下,arg都应该在调用之前的某个时刻由va_start初始化,并期望在调用之后的某个时刻由va_end释放。

形参

指向存储生成的C字符串的缓冲区的指针。
缓冲区应该足够大,能够包含生成的字符串。
format
C字符串,包含一个格式字符串,该格式字符串遵循与printf中的format相同的规范(详细信息请参阅printf)。
arg 
标识用va_start初始化的可变实参列表的一个值。
va_list是<cstdarg>中定义的特殊类型。

返回值
如果成功,则返回写入的字符总数。
如果失败,则返回负数。

用例
/* vsprintf example */
#include <stdio.h>
#include <stdarg.h>

void PrintFError ( const char * format, ... )
{
  char buffer[256];
  va_list args;
  va_start (args, format);
  vsprintf (buffer,format, args);
  perror (buffer);
  va_end (args);
}

int main ()
{
  FILE * pFile;
  char szFileName[]="myfile.txt";

pFile = fopen (szFileName,"r");
  if (pFile == NULL)
    PrintFError ("Error opening '%s'",szFileName);
  else
  {
    // file successfully open
    fclose (pFile);
  }
  return 0;
}
在本例中,如果文件myfile.txt不存在,则调用perror来显示类似如下的错误消息:

C++ Reference: Standard C++ Library reference: C Library: cstdio: vsprintf相关推荐

  1. Conditional project or library reference in Visual Studio

    Conditional project or library reference in Visual Studio In case you were wondering why you haven't ...

  2. link library 、target library、symbol library、synthetic library对照分析-基础小知识(九)

    文章目录 1.1 概念介绍 1.2 疑问解析 参考文档 DC 应用过程中涉及link library .target library.symbol library.synthetic library, ...

  3. undefined reference to `__stack_chk_guard' .. undefined reference to `__stack_chk_fail'

    1. 编译出错 undefined reference to `__stack_chk_guard' undefined reference to `__stack_chk_fail' 解决方法-1: ...

  4. git fatal: cannot lock ref ‘HEAD‘:unable to resolve reference‘refs/heads/main‘:reference broken

    问题: push的时候,电脑强制关机再启动,vscode中所有文件都变成了绿色,暂存待提交状态 当我再次提交时,就出现错误:git fatal: cannot lock ref 'HEAD':unab ...

  5. undefined reference to 'floor'/undefined reference to

    undefined reference to 'floor'/undefined reference to `& undefined reference to 'pow'/undefined ...

  6. 问题排查--@cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken解决方法

    @cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken解决 作者用的是ID ...

  7. C++ Reference: Standard C++ Library reference: C Library: cmath: cbrt

    C++官网参考链接:https://cplusplus.com/reference/cmath/cbrt/ 函数  <cmath> <ctgmath> cbrt C99 dou ...

  8. C++ Reference: Standard C++ Library reference: C Library: cmath: erf

    C++官网参考链接:https://cplusplus.com/reference/cmath/erf/ 函数  <cmath> <ctgmath> erf C99 doubl ...

  9. C++ Reference: Standard C++ Library reference: C Library: cstdio: printf

    C++官网参考链接:https://cplusplus.com/reference/cstdio/printf/ 函数  <cstdio> printf int printf ( cons ...

最新文章

  1. django ajax文件上传,django 之 ajax 篇 上传文件
  2. 软件构造 第一章第二节 软件开发的质量属性
  3. Spring Boot:快速启动MVC
  4. 前后对接数字几_开源数字货币交易所开发学习笔记(1)——系统架构
  5. jdbc获取clob图片_jdbc方式读取oracle的clob字段实例
  6. 寺庙的纪律性也让我颇有感触
  7. 信息学奥赛一本通 1150:求正整数2和n之间的完全数
  8. 300页!2020年全网最新Java面试题(附答案)开放下载!超全!!
  9. Linux查看端口使用情况
  10. java高并发模糊查询,高并发优化
  11. linux build bash,Win10 Build 14316启用Linux Bash 环境图文教程
  12. LoadRunner压力测试实例步骤
  13. 计算机二进制转十进制怎么yun,二进制 十进制 十六进制
  14. django建议入门-FYI
  15. 的计算机基本操作知识,电脑的基本操作知识有哪些
  16. 如何做一名优秀的下属
  17. c语言编译 创建卡号信息表,C语言超市会员信息管理系统源程序
  18. 他本硕博连跨3大专业,毕业后没多久被破格聘为985高校教授!
  19. steam审查元素免费得到几十款游戏教程
  20. NetKeeper(创翼)开WIFI方法——2018.5

热门文章

  1. 使用关键字like进行模糊查询
  2. 存储基础知识 - 传统存储 NAS SAN 和 分布式存储对比
  3. 超详细的计算机视觉学习书籍pdf汇总(涉及CV、深度学习、多视图几何、SLAM、点云处理等)
  4. 怎么成为开源贡献者_我如何成为一名更好的设计师并通过Jolloficons为开源做贡献...
  5. html元素的overflow属性详解
  6. USB PD 3.0快充 (Power Delivery )
  7. SPP (Spatial Pyramid Pooling)
  8. 前端学习(8)下拉框、文本域、文件域
  9. 免费在线恋爱纪念日、结婚纪念日计算器
  10. LWN:在进程级别完成内核相同页面合并(KSM)控制!