240
功不唐捐,玉汝于成😡。

snprintf

函数说明:

最多从源串中拷贝size-1个字符到目标串中,然后再在后面加一个0。所以如果目标串的大小为size的话,将不会溢出。

函数返回值:

若成功则返回欲写入的字符串长度,若出错则返回-1。

头文件:#include<sctdio>

int snprintf(char*str, size_t size,constchar*format, ...);
cout<<snprintf(a,sizeof(a),"%d",5464646)<<' ';
for(int i=0;i<10;i++)
cout<<a[i]<<' ';
运行结果:7 5 4 6 4 6 4 6

sizeof(a)是告诉机器你储存的数组大小,函数返回的是它用了多少

用处:将数字或字符串储存在字符数组中;

posted @ 2019-04-21 11:15  BigXun  阅读(191)  评论(0编辑  收藏  举报