积极答复者
strcpy 用strcpy_s代替,可替换后,出顼错误: 环境Microsoft Visual Studio 2008

问题
-
VC6.0转VS2008,关于strcpy [所有相关帖子]
string.h(74) : error C2733: 不允许重载函数“strcpy_s”的第二个 C 链接
1> h:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : 参见“strcpy_s”的声明
那如何用啊,查了MSDN,在新建立的工程里也出错:
#include "stdafx.h"
#include<iostream>
#include<string.h>
using namespace std;
...
char string[80];
// using template versions of strcpy_s and strcat_s:
strcpy_s( string, "Hello world from " );
strcat_s( string, "strcpy_s " );
答案
-
你好,
根据您所描述的情况编译器错误 C2733,我建议你重新安装或配置您的编译环境。因为C2733的错误提示显示,您可能用 C 链接声明了多个重载函数。但是由于您所链接的是类库中的方法。所以可能是由于环境遭到破坏所引起的。
希望我的建议对您的问题有所帮助
Rob Pan [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Rob Pan 2011年6月2日 1:43
全部回复
-
// crt_strcpy_s.cpp // This program uses strcpy_s and strcat_s // to build a phrase. // #include <string.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> int main( void ) { char string[80]; // using template versions of strcpy_s and strcat_s: strcpy_s( string, "Hello world from " ); strcat_s( string, "strcpy_s " ); strcat_s( string, "and " ); // of course we can supply the size explicitly if we want to: strcat_s( string, _countof(string), "strcat_s!" ); printf( "String = %s\n", string ); }
String = Hello world from strcpy_s and strcat_s!
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development. -
好像还是出错。。不知道为什么。。如下代码|
#include<string.h>#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CCDialogViewIMPLEMENT_DYNCREATE(CCDialogView, CView)
...
void CCDialogView::OnDraw(CDC* /*pDC*/)
{
CCDialogDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;char stringEe[80];
// using template versions of strcpy_s and strcat_s:
strcpy_s( stringEe, "Hello world from " );
strcat( stringEe, "strcpy_s " );// TODO: 在此处为本机数据添加绘制代码
}出错信息:
error C2733: 不允许重载函数“strcpy_s”的第二个 C 链接
1> h:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : 参见“strcpy_s”的声明
1>生成日志保存在“file://e:\VC8\CDialog\CDialog\Debug\BuildLog.htm”点击出错信息,跳到string.h
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcpy_s, _Deref_post_z_ char, _Dest, _In_z_ const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcpy_s, _Pre_cap_for_(_Source) _Post_z_, char, _Dest, _In_z_ const char *, _Source)
#if __STDC_WANT_SECURE_LIB__并且我发现我重新完全建立一个新工程,直接编译也出错。也是这个提示: 不允许重载函数“strcpy_s”的第二个 C 链接
-
问题是没有解决啊,你说的这行代码是没问题。
问题是我现在好像2008那个地方设置了一样,直接编译也出错。也是这个提示: 不允许重载函数“strcpy_s”的第二个 C 链接
完全新建立一个工程,没用strcpy和strcpy_s也出错。击出错信息,跳到string.h
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcpy_s, _Deref_post_z_ char, _Dest, _In_z_ const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcpy_s, _Pre_cap_for_(_Source) _Post_z_, char, _Dest, _In_z_ const char *, _Source)
#if __STDC_WANT_SECURE_LIB__ -
你好,
根据您所描述的情况编译器错误 C2733,我建议你重新安装或配置您的编译环境。因为C2733的错误提示显示,您可能用 C 链接声明了多个重载函数。但是由于您所链接的是类库中的方法。所以可能是由于环境遭到破坏所引起的。
希望我的建议对您的问题有所帮助
Rob Pan [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Rob Pan 2011年6月2日 1:43