关于strcpy_s

Posted 注销了

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于strcpy_s相关的知识,希望对你有一定的参考价值。

#include"stdafx.h"
#include<iostream>
#include<cstring>
int main()
{
    using namespace std;

    char animal[20] = "bear";
    const char* bird = "wren";
    char* ps;

    cout << "Enter a kind of animal: ";
    cin >> animal;
    ps = animal;

    cout << "Before using strcpy_s(): " << endl;
    cout << animal << " at " << (int *)animal << endl;
    cout << ps << " at " << (int*)ps << endl;

    ps = new char[strlen(animal) + 1];
    cout << "sizeof ps: " << sizeof ps << endl;
    strcpy_s(ps,strlen(animal)+1, animal);
    cout << "After using strcpy_s(): " << endl;
    cout << animal << " at " << (int *)animal << endl;
    cout << ps << " at " << (int*)ps << endl;

    delete [] ps;
    cin.get();
    cin.get();
    return 0;
}

strlen 三个参数的情况下,第二个参数表示numberOfElements 

以上是关于关于strcpy_s的主要内容,如果未能解决你的问题,请参考以下文章

例外:使用 strcpy_s 时访问冲突写入位置

strcpy_s 是如何工作的?

当我使用模板时,未在此范围GCC Linux环境中声明strerror_s,strcpy_s,localtime_s,sprintf_s?

关于代码片段的时间复杂度

如何避免 strcpy_s 缓冲区太小

如何将当前的 strcpy 转换为 strcpy_s?