hcfan

strcpy_s和strcpy()函数的功能几乎是一样的。

strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它只能假定缓冲足够大来容纳要拷贝的字符串。在程序运行时,这将导致不可预料的行为。用strcpy_s就可以避免这些不可预料的行为。

strcpy_s 一般使用三个参数

errno_t strcpy_s(
char *strDestination,
size_t numberOfElements,
const char *strSource
);

CString str0 = "这是一个测试";
int num = str0.GetLength();
char* result = new char[num + 1];
strcpy_s(result, num + 1, str0);
View Code

注意数组长度要加1,否则会进行报错。

分类:

技术点:

相关文章:

  • 2021-05-30
  • 2022-12-23
  • 2021-11-04
  • 2021-12-09
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案