This is a C++ Program to Concatenate two C-Style strings.
The program takes two strings and concatenates them, as in links them together.
1. The program takes two strings initially.
2. Using string function, the two strings are concatenated.
3. The concatenated string is printed.
4. Exit.
Here is the source code of C++ Program to Concatenate Two Strings. The program output is shown below.
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
char str1[50], str2[50];
cout << "Enter string 1 : ";
gets(str1);
cout << "Enter string 2 : ";
gets(str2);
strcat(str1, str2);
cout << "Concatenated String : " << str1;
return 0;
}
1. The user is asked to enter two strings. They are stored in the character variables ‘str1′ and str2’.
2. Using ‘strcat()’, which is an inbuilt function under the library ‘string.h’, the two strings are concatenated.
3. The concatenated string is stored in str1.
4. The result is then printed.
Case 1 : Enter string 1 : Hello Enter string 2 : World Concatenated String : Hello World Case 2 : Enter string 1 : 24 Enter string 2 : 68 Concatenated String : 2468 Case 3 : Enter string 1 : C++ Enter string 2 : Programming Concatenated String : C++Programming
Sanfoundry Global Education & Learning Series – C++ Programs.
To practice all C++ programs, here is complete set of 1000+ C++ Programming examples.
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C++ Internship
- Buy C++ Books
- Apply for Information Technology Internship
- Buy Computer Science Books
- Buy Programming Books