c++
2014-04-29 09:23
246 查看
int snprintf ( char * s, size_t n, const char * format, ... );
Write formatted output to sized buffer
Composes a string with the same text that would be printed if format was used onprintf, but instead of being printed, the content is stored as aC string in the buffer pointed by
s (taking n as the maximum buffer capacity to fill).
If the resulting string would be longer than n-1 characters, the remaining characters are discarded and not stored, but counted for the value returned by the function.
A terminating null character is automatically appended after the content written.
After the format parameter, the function expects at least as many additional arguments as needed forformat.
sPointer to a buffer where the resulting C-string is stored.
The buffer should have a size of at least n characters.nMaximum number of bytes to be used in the buffer.
The generated string has a length of at most n-1, leaving space for the additional terminating null character.
size_t is an unsigned integral type.formatC string that contains a format string that follows the same specifications asformat in
printf (seeprintf 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 aformat specifier in the
format string (or a pointer to a storage location, forn).
There should be at least as many of these arguments as the number of values specified in theformat specifiers. Additional arguments are ignored by the function.
The number of characters that would have been written if n had been sufficiently large, not counting the terminatingnull character.
If an encoding error occurs, a negative number is returned.
Notice that only when this returned value is non-negative and less than n, the string has been completely written.
/* snprintf example */ #include <stdio.h> int main () { char buffer [100]; int cx; cx = snprintf ( buffer, 100, "The half of %d is %d", 60, 60/2 ); snprintf ( buffer+cx, 100-cx, ", and the half of that is %d.", 60/2/2 ); puts (buffer); return 0; }
相关文章推荐
- 编程宝典 保持C/C++程序代码可伸缩性
- borland c++ bulder的文件操作总结
- C++知识要点
- C++代码静态分析工具
- C++的2个易错点
- Inside the C++ Object Model 读书笔记
- c/c++中#include 与#include""区别
- c++文件复制
- C/C++数组名与指针区别深入探索
- C++ vector 删除
- C++变量的初始化方式
- C++功在不舍(2012.07.07)
- Stack的c++实现(不完整)
- C++ Get System Time
- vector 在c++中resize 和reserve的区别
- C++内存分配的五种方法的区别
- Thinking in C++: 函数的参数传递方法
- windows 7 Microsoft Visual C++ 2005 Redistributable -- Error 1935.安装程序
- 标准C++中的string类的用法总结
- c++内存管理 01