C4996错误的意思:是VS觉得strcpy这函数不安全,建议你使用更安全的函数。
C4996错误的解决方法:
- 屏蔽出996错误(在程序前添加如下代码)
#pragma warning(disable:4996)
- 使用编译器推荐的更安全的strcpy_s函数(s的意思是safe)
CString str0 = "这是一个测试";
char* result = new char[str0.GetLength() + 1];
strcpy_s(result, str0.GetLength() + 1, str0);
注意数组长度要+1,不然会报错。
推荐使用第一种方法,一劳永逸,因为第二种有可能还有其他的函数需要改,如scanf要改成scanf_s等。