C++ strcat() Function
C++ strcat() function joins two strings together.
It concatenates source string at the end of destination string.
Syntax:
strcat(string1(source string), string 2(destination string));
Here string1 and string2 are character arrays. When strcat function is executed, string2 is appended to string1. It does removing the null character at the end of string1 and placing string2 from there. The string at string2 remains unchanged.
Example:
#include <iostream> #include <cstring> using namespace std; int main () { char str1[30] = "Welcome to"; char str2[30] = " Onlinetpoint"; int str3; /* concatenates str1 and str2 */ strcat( str1, str2); cout << "String concatenate str1 & str2: " << str1 << endl; /* length of string str1 */ str3=strlen( str1); cout << "Length of string str1 is: "<< str3 ; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.