我得到一个“strcpy的”错误和以下行警告:“strcpy的”错误和警告
_tcscpy(strCommandLine,_T("MyProgram.exe /param1"));
_tcscpy(strApplicationName,_T("MyProgram.exe"));
不知道为什么我得到一个“strcpy的”错误或警告,因为我不使用'strcpy'。与此相关的唯一线路是:
LPCTSTR strApplicationName;
LPTSTR strCommandLine;
_tcscpy(strCommandLine,_T("MyProgram.exe /param1")); //warning is on this line
_tcscpy(strApplicationName,_T("MyProgram.exe")); //error is on this line
输出是:
1>c:\documents and settings\X.X\my documents\sandbox\sample.cpp(52) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\string.h(74) : see declaration of 'strcpy'
1>c:\documents and settings\X.X\my documents\sandbox\sample.cpp(53) : error C2664: 'strcpy' : cannot convert parameter 1 from 'LPCTSTR' to 'char *'
1> Conversion loses qualifiers
上,这可能意味着什么?任何想法?
这些都是我的头:
iostream
windows.h
stdio.h
tchar.h
winnt.h
'strcpy'被隐藏在宏的下面或所以在这里;正如OP所提到的,他们得到了一些不是'strcpy'的警告。 – Joey 2010-04-22 17:27:24
我认为最好使用strncpy作为标准的C++而不是strcpy_s,这似乎是一个MS事物。 – 2010-04-22 18:37:17