zoukankan      html  css  js  c++  java
  • C plus plus sprintf用法

    sprintf

    int sprintf ( char * str, const char * format, ... );
    Write formatted data to string
    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"





  • 相关阅读:
    php面试专题---2、常量及数据类型考点
    php面试专题---3、运算符考察点
    php面试专题---1、php中变量存储及引用的原理
    html中map标签和area标签的应用(总结)
    nginx中如何设置gzip(总结)
    PHP缓存技术OB系统函数(总结)
    Http协议面试题(总结)
    剑指offer 例题
    程序的模块化的一些见解6-读牛人代码之感
    oracle dblink造成远程数据库session过多
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9387111.html
Copyright © 2011-2022 走看看