代码如下,显示错误
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.
#include<iostream>
#include<string.h>
using namespace std;
char *getname(void);//function prototype
int main()
{
char *name;
name = getname();
cout << name << "at" << (int *)name << "\n";
delete[] name;//why use delete?
name = getname();
cout << name << " at " << (int *)name << "\n";
system("pause");
delete[] name;//why use delete? because return pn
return 0;
}
char *getname()
{
char temp[80];//temporary storage
cout << "enter last name" << endl;
cin >> temp;
char *pn = new char[strlen(temp) + 1];
strcpy(pn, temp);
return pn;
}
解决方案:
项目->项目属性->C/C++ ->预处理器-》预处理器定义 下编辑中添加下面即可
_CRT_SECURE_NO_WARNINGS