|
发表于 2023-9-10 16:47:29
|
显示全部楼层
本楼为最佳答案
这些错误是由于使用了不安全的函数而导致的。Visual Studio 2019建议使用更安全的替代函数。
你可以按照编译器的建议进行修改,使用更安全的函数代替。
对于`fopen`,你可以使用`fopen_s`来替代:
- if (fopen_s(&fp, filename, "r") != 0)
- {
- fprintf(stderr, "Can not open the file:%s\n", filename);
- return 0;
- }
复制代码
对于`strcpy`和`strcat`,你可以使用`strcpy_s`和`strcat_s`来替代:
- strcpy_s(thePath, MAX, path);
- strcat_s(thePath, MAX, "/*.c");
复制代码
对于`sprintf`,你可以使用`sprintf_s`来替代:
- sprintf_s(target, MAX, "%s/%s", path, fa.name);
复制代码
这样修改后,你的代码应该可以在Visual Studio 2019中编译通过了。 |
|