sprintf到底会不会在生成字符串结尾添加0?

tw 2014-09-04 09:20:22
windows下(VC2012)

string str = "";
char strdatacode[8];
sprintf(strdatacode, "%d", 123321);
str += strdatacode;
cout << str << endl;
system("pause");

输出 123321

linux下呢?
...全文
1578 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tw 2014-09-04
  • 打赏
  • 举报
回复
引用 3 楼 micropentium6 的回复:
[quote=引用 2 楼 a5882230 的回复:] [quote=引用 1 楼 mymtom 的回复:] 必须有啊!!!
http://bbs.csdn.net/topics/300160076 这个帖子说没有啊[/quote] it's ironic, isn't it? mymtom is the moderator of c/c++ board... [/quote] what's the correct answer?
707wk 2014-09-04
  • 打赏
  • 举报
回复
自己实际编译一下就什么都清楚了
  • 打赏
  • 举报
回复
引用 2 楼 a5882230 的回复:
[quote=引用 1 楼 mymtom 的回复:] 必须有啊!!!
http://bbs.csdn.net/topics/300160076 这个帖子说没有啊[/quote] it's ironic, isn't it? mymtom is the moderator of c/c++ board...
tw 2014-09-04
  • 打赏
  • 举报
回复
引用 1 楼 mymtom 的回复:
必须有啊!!!
http://bbs.csdn.net/topics/300160076 这个帖子说没有啊
mymtom 2014-09-04
  • 打赏
  • 举报
回复
必须有啊!!!
tw 2014-09-04
  • 打赏
  • 举报
回复
引用 7 楼 mymtom 的回复:
[quote=引用 2 楼 a5882230 的回复:] [quote=引用 1 楼 mymtom 的回复:] 必须有啊!!!
http://bbs.csdn.net/topics/300160076 这个帖子说没有啊[/quote] 说不会的人已经被老板开除了,现在在码头搬货! [/quote] 谢谢恶魔猎手!
mymtom 2014-09-04
  • 打赏
  • 举报
回复
引用 2 楼 a5882230 的回复:
[quote=引用 1 楼 mymtom 的回复:] 必须有啊!!!
http://bbs.csdn.net/topics/300160076 这个帖子说没有啊[/quote] 说不会的人已经被老板开除了,现在在码头搬货!
mymtom 2014-09-04
  • 打赏
  • 举报
回复
这个是很基本的问题,答案很明确的 C89 4.9.6.5 The sprintf function Synopsis #include <stdio.h> int sprintf(char *s, const char *format, ...); Description The sprintf function is equivalent to fprintf , except that the argument s specifies an array into which the generated output is to be written, rather than to a stream. A null character is written at the end of the characters written; it is not counted as part of the returned sum. If copying takes place between objects that overlap, the behavior is undefined. Returns The sprintf function returns the number of characters written in the array, not counting the terminating null character.

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧