Here you will get C++ program to concatenate two string without using library function.
在这里,您将获得C ++程序来连接两个字符串而不使用库函数。
Below program will read two strings from user and then concatenate them to form third string.
下面的程序将从用户读取两个字符串,然后将它们连接起来以形成第三个字符串。
#include<iostream>
using namespace std;
int main()
{
char str1[30],str2[30],str3[60];
int i,j;
cout<<"Enter first string:";
gets(str1);
cout<<"\nEnter second string:";
gets(str2);
for(i=0;str1[i]!='\0';++i)
str3[i]=str1[i];
for(j=0;str2[j]!='\0';++j)
str3[i+j]=str2[j];
str3[i+j]='\0';
cout<<"\nThe concatenated string is "<<str3;
return 0;
}
Output
输出量
Enter first string:Hello
输入第一个字符串:你好
Enter second string:World
输入第二个字符串:World
The concatenated string is HelloWorld
串联的字符串是HelloWorld
翻译自: https://www.thecrazyprogrammer.com/2011/03/c-program-to-concatenate-two-strings-2.html
|