“sprintf”: 不允许重载函数的第二个 C 链接

C++语言 码拜 7年前 (2017-05-04) 4960次浏览
用VS2015写的一个Win32应用程序,出现了一个问题,不知道怎么解决了,报错如下:
错误 C2733 “sprintf”: 不允许重载函数的第二个 C 链接
<stdio.h>
#if __STDC_WANT_SECURE_LIB__
_Success_(return >= 0)
_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL sprintf(
_Out_writes_z_(_BufferCount)  char*       const _Buffer,
_In_                          size_t      const _BufferCount,
_In_z_ _Printf_format_string_ char const* const _Format,
…)
#if defined _NO_CRT_STDIO_INLINE
;
<Com_p1.cpp>
switch(nCmd)
{
case C1_TIME:  /*设定时间*/
//sprintf(szSend,”%s %s\r”,”WRS DM200 2 %s\r”,strNum);
sprintf(szSend,”%c1119004%s%c”,0x02,FormatLongToDmFx(szcode,nValue,2),0x03);
strcat(szSend,GetBBCCode(szcode,szSend,1));
break;
case C1_SPEED: /*设定速度*/
//sprintf(szSend,”%s %s\r”,”WRS DM260 2 %s\r”,strNum);
sprintf(szSend,”%c1120804%s%c”,0x02,FormatLongToDmFx(szcode,nValue,2),0x03);
strcat(szSend,GetBBCCode(szcode,szSend,1));
break;
}
解决方案

10

启用了安全库 __STDC_WANT_SECURE_LIB__
VS重载了sprintf函数,原因是都是c链接的所以会导致冲突
要么关闭这个宏定义,要么不要包含stdio.h这个头文件,纯使用vs版本的

15

在.cpp的第一行前面添加:
#undef __STDC_WANT_SECURE_LIB__
#define _NO_CRT_STDIO_INLINE

15

#pragma warning(disable:4996)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明“sprintf”: 不允许重载函数的第二个 C 链接
喜欢 (1)
[1034331897@qq.com]
分享 (0)