我想在 Visual C++ 6.0(普通 C)中 sprintf() 一个无符号 long long 值。
char buf[1000]; //bad coding
unsigned __int64 l = 12345678;
char t1[6] = "test1";
char t2[6] = "test2";
sprintf(buf, "%lli, %s, %s", l, t1, t2);
给出结果
12345678, (null), test1
(注意那个test2
未打印)
and l = 123456789012345
它给出了一个异常句柄
有什么建议么?
打印一个unsigned __int64
您应该使用 Visual C++ 6.0 中的值%I64u
, not %lli
(参考这一页 http://msdn.microsoft.com/en-us/library/aa272936%28VS.60%29.aspx在 MSDN 上)。%lli
仅在 Visual Studio 2005 及更高版本中受支持。
所以,你的代码应该是:
sprintf(buf, "%I64u, %s, %s", l, t1, t2);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)