c++字符串相连函数
// 介绍两种方法,源程序如下:
//////////////////////////////////////////////////////////////////////
// 方法一:#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;
}
*/




浙公网安备 33010602011771号