// 介绍两种方法,源程序如下:
//////////////////////////////////////////////////////////////////////
// 方法一:#include <cstring>
#include <iostream>
#include <cstring>
using namespace std;
void main()
{
string str1 = "abc";
string str2 = "def";
cout << "方法一:#include<cstring>" << endl;
cout << "连接前:" << endl;
cout << "str1: " << str1.data() << endl;
cout << "str2: " << str2.data() << endl;
str1.append(str2);
cout << endl;
cout << "连接后:" << endl;
cout << "str1: " << str1.data() << endl;
cout << "str2: " << str2.data() << endl;
}
/////////////////////////////////////////////////////////////////////
// 方法二:#include <string.h>
/*
#include <iostream.h>
#include <string.h>
void main()
{
char str1[10] = "abc", str2[] = "def";
cout << "方法二:#include <string.h>" << endl;
cout << "连接前:" << endl;
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << endl;
strcat(str1,str2);
cout << endl;
cout << "连接后:" << endl;
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << endl;
}
*/
原文链接: https://www.cnblogs.com/zsh2016/p/5799226.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/239209
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!