相关疑难解决方法(0)

为什么strcpy_s比strcpy更安全?

当我尝试使用该strcpy功能时,视觉工作室给我一个错误

error 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.
Run Code Online (Sandbox Code Playgroud)

在网上搜索和 StackOverflow 的许多答案之后,总结是这比将大字符串复制到较短的字符串strcpy_s更安全。strcpy因此,我尝试使用以下代码来处理较短的字符串:

char a[50] = "void";
char b[3];
strcpy_s(b, sizeof(a), a);
printf("String = %s", b);
Run Code Online (Sandbox Code Playgroud)

代码复制成功。但是,仍然存在运行时错误: 在此输入图像描述

那么,怎样才scrcpy_s安全呢?我对安全概念的理解错误吗?

c string strcpy

1
推荐指数
1
解决办法
1810
查看次数

标签 统计

c ×1

strcpy ×1

string ×1