To program the connection between two strings, you must use a character array to save the strings without using system functions.
Algorithm: First define two character arrays in the main function. The last character of the character array is 0, and it is treated as the termination condition of the loop, first point a pointer to the last character of the first string, and then copy the characters in the second string to the first string in sequence.
Code:
# Include <iostream. h>
Void main ()
{
Char A [20], B [10];
Cout <"Enter the value of the two character Arrays:" <Endl;
Cin>;
Cin> B;
For (INT I = 0; I! = '/0'; I ++)
For (Int J = 0; (a [I] = B [J])! = '/0'; I ++, J ++)
Cout <"after the two strings are connected:" <Endl;
Cout <A <Endl;
}
Use the string class to define the string object and implement the previous question again
Algorithm: the string class can be used as a special character array. You only need to define two objects in the main function and then use the overloaded operator + = to complete the connection function.
Code:
# Include <iostream>
# Include <string>
Using namespace STD;
Void main ()
{
String A, B;
Cout <"Enter these two string types:" <Endl;
Cin> A> B;
A + = B;
Cout <"value after connection:" <A <Endl;
}