string型字符串的替换-strncpy

来源:互联网 发布:mac怎么连接无线键盘 编辑:程序博客网 时间:2024/06/07 11:57

strncpy有三个参数 第一个参数是要替换的字符串 第二个是源字符串,第三个替换的字符个数

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
char ch1[10]="gh";
char ch2[]="abcdef";
strncpy(ch1,ch2,3);
//ch1要替换的字符安串,ch2源字符串,要替换的字符个数
cout<<ch1<<endl;
return 0;
}