第十八章 5strncat函数的使用 简单

#include <iostream>
using namespace std;
int main()
{
    char ch1[10] = "ab";
	char ch2[] = "abcdef";
	strncat(ch1,ch2,3); //ababc 合并char类型的字符串,第三个参数是指需要合并的字符串个数
	cout<<ch1<<endl;
	return 0;
}
//相对应的是string类的append成员函数的使用
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str1="str1";
	string str2="hello word";
	str1.append(str2,2,3); //str1llo
	cout<<str1<<endl;
    return 0;
}

  

原文地址:https://www.cnblogs.com/xiangxiaodong/p/2694528.html