美文网首页
C++之string转char数组strcpy_s

C++之string转char数组strcpy_s

作者: KingOfLion | 来源:发表于2019-05-31 23:04 被阅读0次

在C++标准库中有一个strcpy_s函数,该函数的前身是strcpy,但是因为strcpy_s是安全的,而strcpy并不安全,所以现在使用strcpy_s。

1、strcpy_s的用法:

include <string>//首先导入头文件

include <iostream>

using namespace std;

public void main(){

//第一种用法

char ch[100];//定义一个数组

string str = "我在使用strcpy_s";//定义一个字符串 

strcpy_s(ch,str);

cout<<ch<<endl;

//第二种用法

char *ch=null;//定义一个字符型指针

ch = char cha[20];

strcpy_s(ch,20,"我在使用strcpy_s函数。");//必须填入三个变量

}

作者:ThreeLearning
来源:CSDN
原文:https://blog.csdn.net/king_java2020/article/details/79822869
版权声明:本文为博主原创文章,转载请附上博文链接!

相关文章

网友评论

      本文标题:C++之string转char数组strcpy_s

      本文链接:https://www.haomeiwen.com/subject/clmntctx.html