gpt4 book ai didi

c++ - 微软 _stprintf 警告

转载 作者:可可西里 更新时间:2023-11-01 17:55:28 31 4
gpt4 key购买 nike

为什么我收到以下代码的以下警告:)

代码:

_stprintf(m_szFileNamePath,_T("%s"),strFileName);

warning C4996: '_swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set _CRT_NON_CONFORMING_SWPRINTFS.

我知道 _strprintf 是一个宏,如果定义了 _UNICODE,它的计算结果将是 _swprintf,否则它将是 sprintf。

现在这个 _swprintf 是什么。有一个函数 swprintf,但为什么 _stprintf 计算为 _swprintf 而不是 swprintf。

_xxx 和 xxx 函数有什么区别?

编辑:

好吧,_stprintf 的 UNICODE 版本有两个定义,包含哪一个?

tchar.h 或 strsafe.h 中的那个?

最佳答案

http://msdn.microsoft.com/en-us/library/ybk95axf%28VS.80%29.aspx

swprintf is a wide-character version of sprintf; the pointer arguments to swprintf are wide-character strings. Detection of encoding errors in swprintf may differ from that in sprintf. swprintf and fwprintf behave identically except that swprintf writes output to a string rather than to a destination of type FILE, and swprintf requires the count parameter to specify the maximum number of characters to be written. The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

In Visual C++ 2005, swprintf conforms to the ISO C Standard, which requires the second parameter, count, of type size_t. To force the old nonstandard behavior, define _CRT_NON_CONFORMING_SWPRINTFS. In a future version, the old behavior may be removed, so code should be changed to use the new conformant behavior.

关于c++ - 微软 _stprintf 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1293889/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com