#include"stdafx.h"
#include<iostream>
#include<cstring>
int main()
{
using namespace std; char animal[] = "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) + ];
cout << "sizeof ps: " << sizeof ps << endl;
strcpy_s(ps,strlen(animal)+, 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 ;
}

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

关于strcpy_s的更多相关文章

  1. 对 strcpy_s 若干测试

    今天发现如果strcpy这函数,目标buffer太小,会有意想不到的崩溃.而且不容易调试.以后尽量要用strcpy_s了. strcpy_s是strcpy的更安全的版本 1.当目标字符串参数是一个字符 ...

  2. wcscpy wcscpy_s strcpy strcpy_s的区别

    原型声明:extern char *strcpy(char *dest,const char *src); 头文件:string.h 功能:把从src地址开始且含有NULL结束符的字符串赋值到以des ...

  3. strcpy_s与strcpy的比較

    strcpy_s和strcpy()函数的功能差点儿是一样的.strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它仅仅能假定缓冲足够大来容纳要拷贝的字符串.在程序执行时,这将 ...

  4. 新版本的strcpy_s

    char a[32] = "1234"; char b[32] ="123"; strcpy_s(b,sizeof(b), a + 2);//可以用strlen ...

  5. strcpy_s

    char src[5]="abcd"; char *des=new char[str.length(src)+1];   // length()不计\0 strcpy_s(des, ...

  6. C++ strcpy strcpy_s strncpy strlcpy

    strncpy的用法:它与strcpy的不同之处就在于复制n个字符,而不是把所有字符拷贝(包括结尾'\0'). 函数原型:char * strncpy(char *dst,const char * s ...

  7. strcpy_s与strcpy对照

    strcpy_s和strcpy()函数功能几乎相同.strcpy函数.就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它仅仅能假定缓冲足够大来容纳要拷贝的字符串.在程序执行时,这将导致不可 ...

  8. C++string函数之strcpy_s

    strcpy_s和strcpy()函数的功能几乎是一样的.strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它只能假定缓冲足够大来容纳要拷贝的字符串.在程序运行时,这将导致 ...

  9. strcpy_s和strcpy()

    转自: https://www.cnblogs.com/hrhguanli/p/4570093.html strcpy_s和strcpy()函数功能几乎相同.strcpy函数.就象gets函数一样,它 ...

随机推荐

  1. 数据库多对多关联表(Python&MySQL)

    Python Python对MySQL数据库操作使用的是sqlalchemy这个ORM框架 #一本书可以有多个作者,一个作者又可以出版多本书 from sqlalchemy import Table, ...

  2. mac os x安装php7.0和phalcon3.0

    1,安装xampp(with php7.0) 下载地址: https://www.apachefriends.org/download.html 2,安装phalcon3.0 cd ~/git clo ...

  3. linux上进程状态查询

    linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有 ...

  4. 《转载》化繁为简 如何向老婆解释MapReduce?

    本文转载自http://server.zol.com.cn/329/3295529.html 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解M ...

  5. POJ 1917

    http://poj.org/problem?id=1917 poj的字符串的一道水题. 题意么无关紧要, 反正输出的第一行就是把那个<>去掉,s1<s2>s3<s4&g ...

  6. lists删除

    List<Map<String, Object>> trackList = bizFollowRepo.findList("trackFindPageList&quo ...

  7. 针对跑MySQL的Linux优化【转】

    本文来自:http://www.mysqlsupport.cn/linux-performance-tuning-tips-mysql/ 因为很多MySQL的生产环境都在Linux下,我决定指出一些L ...

  8. MySQL 通过idb文件恢复Innodb 数据【转】

    昨晚收到一则求助,一个用户的本地数据库的重要数据由于误操作被删除,需要进行紧急恢复,用户的数据库日常并没有进行过任何备份,binlog也没有开启,所以从备份和binlog入手已经成为不可能,咨询了丁奇 ...

  9. Java for LeetCode 237 Delete Node in a Linked List

    Java实现如下: public class Solution { public void deleteNode(ListNode node) { if(node==null||node.next== ...

  10. codeforces 557B. Pasha and Tea 解题报告

    题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...