4个回答
2013-06-10
展开全部
// 介绍两种方法,源程序如下://////////////////////////////////////////////////////////////////////
// 方法一:#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;
}
*/
// 方法一:#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;
}
*/
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-04-02 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464984
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
#include<stdio.h>
void main()
{char s1[80],s2[40];
int i=0,j=0;
printf("\ninput string1:");
scanf("%s",s1);
printf("input string2:");
scanf("%s",s2);
while(s1[i]!='\0')
i++;
while(s2[j]!='\0')
s1[i++]=s2[j++];
s1[i]='\0';
printf("The new string is:%s\n",s1);
}
void main()
{char s1[80],s2[40];
int i=0,j=0;
printf("\ninput string1:");
scanf("%s",s1);
printf("input string2:");
scanf("%s",s2);
while(s1[i]!='\0')
i++;
while(s2[j]!='\0')
s1[i++]=s2[j++];
s1[i]='\0';
printf("The new string is:%s\n",s1);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-10
展开全部
char *strcat( char *strDestination, const char *strSource );wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );ParametersstrDestination Null-terminated destination string strSource Null-terminated source string LibrariesAll versions of the C run-time libraries.Return ValueEach of these functions returns the destination string (strDestination). No return value is reserved to indicate an error.RemarksThe strcat function appends strSource to strDestination and terminates the resulting string with a null character. The initial character of strSource overwrites the terminating null character of strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcat is undefined if the source and destination strings overlap.wcscat is the wide-character version of strcat. The arguments and return value of wcscat are wide-character strings. These two functions behave identically otherwise.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-10
展开全部
你好,比如下边这个#include <string>#include <iostream>using namespace std;void main(){ char a[50],b[50]; cin>>a>>b; cout<<strcat(a,b)<<endl;; }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询