第十八章 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;
}

  

posted @ 2012-09-20 00:05  简单--生活  阅读(376)  评论(0编辑  收藏  举报
简单--生活(CSDN)