问题描述
微软的 如果定义了 _UNICODE
,则定义 _stprintf
为 swprintf
,否则定义 sprintf
.但是这些函数采用不同的参数!在 swprintf
中,第二个参数是缓冲区大小,但 sprintf
没有.
Microsoft's <tchar.h> defines _stprintf
as swprintf
if _UNICODE
is defined, and sprintf
if not. But these functions take different arguments! In swprintf
, the second argument is the buffer size, but sprintf
doesn't have this.
有人偷懒了吗?如果是这样,这是一个很大的问题.如何在我的程序中使用 _stprintf
,并让它们在有和没有 _UNICODE
的情况下工作?
Did somebody goof? If so, this is a big one. How can I use _stprintf
in my programs, and have them work with and without _UNICODE
?
推荐答案
您在这里看到了并行发展.swprintf
是标准 C 的后来者,在发现 (A) 8 位不足以容纳文本并且 (B) 您应该将缓冲区大小与缓冲区一起传递.TCHAR
是微软统一 ASCII 和 Unicode API 的想法.他们丢球,丢了点 (B).正确的TCHAR
解决方案应该是将_stprintf
定义为swprintf
或snprintf
.
You're seeing parallel evolution here. swprintf
is a latecomer to standard C, after it was discovered that (A) 8 bits is insufficient for text and (B) you should pass buffer sizes along with buffers. TCHAR
is a microsoft idea to unify ASCII and Unicode APIs. They dropped the ball, missing point (B). The proper TCHAR
solution should have been to define _stprintf
as either swprintf
or snprintf
.
解决方案是简单地包装 <tchar.h>
并自己完成.
The solution is then to simply wrap <tchar.h>
and do this yourself.
这篇关于我如何在我的程序中使用 _stprintf,有和没有 UNICODE 支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!