把下面代码加到某个头文件中,放在最后include, 或者直接放在cpp文件上面
#if defined(WIN32) || defined(WIN64)
// windows platform
# ifdef _MSC_VER
# if (_MSC_VER >= 1800)
#define strcpy(dest,src)
strcpy_s(dest,strlen(src)+1,src)
#define strcat(dest,src)
strcat_s(dest,strlen(dest)+strlen(src)+1,src)
# endif
# endif
# endif
本文介绍在Windows平台上,使用Visual Studio编译器时,如何替换不安全的字符串操作函数strcpy和strcat,以避免缓冲区溢出等安全问题。通过定义宏的方式,将这两个函数替换为更安全的strcpy_s和strcat_s版本。
1188





