码迷,mamicode.com
首页 > 其他好文 > 详细

关于strcpy_s

时间:2016-10-26 00:58:32      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:nbsp   return   style   eof   std   []   for   cin   div   

#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

标签:nbsp   return   style   eof   std   []   for   cin   div   

原文地址:http://www.cnblogs.com/heben/p/5998682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!