Concatenate two strings c++: In the previous article, we have discussed C++ Program to Find the Length of a String. In this article, we will see C++ Program to Concatenate Two Strings.
C++ Program to Concatenate Two Strings
- How to concatenate two strings without using strcat function.
- C++ program to concatenate two input strings using while loop.
C++ program to concatenate two strings
#include <iostream> #include <cstring> using namespace std; int main(){ char first[1000], second[1000]; int i = 0, len; cout << "Enter first string"<< endl; cin.getline(first, 1000); cout << "Enter second string"<< endl; cin.getline(second, 1000); len = strlen(first); while(second[i] != '\0'){ first[len] = second[i]; len++; i++; } first[len] = '\0'; cout << "Concatenated String"<< endl<< first; return 0; }
Output
Enter first string Btech Enter second string Btechgeeks Concatenated String BTechGeeks
Do you want to learn how to write a simple program in C++ language? If yes, then tap on the C++ Sample Programs link and get the source code for sample and easy programs.