Linchakin

3rd Sep - How to concatenate two strings in c++

 September 03, 2021     No comments   

This section will discuss the concatenation of two or more strings in the C++ programming language. The concatenation of the string means the group of characters that combines two more strings to return a concatenated single string. While concatenating the strings, the second string is added at the end of the first string to make a single string.

For example, we have two strings, 'Java' and 'Tpoint', and we want to concatenate to make a single string as Java + Tpoint = JavaTpoint.

How to concatenate two strings in c++

Let's discuss the different ways to concatenate the given string in the C++ programming language.

  1. Concatenate two strings using for loop
  2. Concatenate two strings using while loop
  3. Concatenate two strings using the + operator
  4. Concatenate two strings using the strcat() function
  5. Concatenate two strings using the append() function
  6. Concatenate two strings using inheritance
  7. Concatenate two strings using friend function and strcat() function

Program to concatenate two strings using for loop

Let's consider an example to combine two strings using for loop in the C++ programming.

Program.cpp

Output

  Enter the first string: Java
Enter the second string: Tpoint
The Concatenation of the string Java and Tpoint is JavaTpoint

Program to concatenate two strings using while loop

Let's consider an example to combine two strings using a while loop in C++ programming.

Program2.cpp

Output

The first string is:  We Love
The second string is: C++ Programming Language
The concatenated string is: We Love C++ Programming Language

Program to concatenate two strings using the + operator in C++

+ Operator: It is an arithmetic '+'operator that simply adds two strings to return a new concatenated string.

Let's consider an example to combine two strings using the + operator in C++ programming.

Program3.cpp

Output

Enter the first string: Java
Enter the second string: Tpoint
The concatenated string Java and Tpoint is: JavaTpoint

Program to concatenate two strings using the strcat() method

strcat() function: The strcat is an inbuilt function of the string class, which adds two character strings to return a concatenated string.

Syntax

There are two character arrays in the above syntax, arr1 and arr2, which passed inside the strcat() function to return a concatenated string.

Let's consider an example to combine two strings using strcat() function in the C++ programming.

Program4.cpp

Output

String 1:  We love
String 2: C++ Programming
The concatenated string is: We love C++ Programming

Program to concatenate two strings using the append function

append() function: An append() function is a predefined library function used to insert or add a second string at the end of the first string to return a single string.

Syntax

In the above syntax, the str2 is a second string to pass in the append() function that inserts the str2 string at the end of the str1 string.

Let's consider an example to combine two strings using append() function in the C++ programming.

Program5.cpp

Output

  Enter the first string: Hello
Enter the second string: Friends!

The concatenation of the string is: HelloFriends!

Program to concatenate two string using the inheritance of the class

Let's consider an example to combine two strings using inheritance in the C++ programming.

Program6.cpp

Output

Enter first string: C++

Enter second string: Programming

The concatenated string is: C++Programming

Program to concatenate two strings using the friend function and strcat() function

Let's consider an example to combine two strings using friend function and strcat() function in the C++ programming.

Program7.cpp

Output

Enter the first string: javatpoint
Enter the second string: .com
The concatenated string: javatpoint.com

Adblock test (Why?)


You may be interested in:
>> Is a Chromebook worth replacing a Windows laptop?
>> Find out in detail the outstanding features of Google Pixel 4a
>> Top 7 best earbuds you should not miss

Related Posts:
>> Recognizing 12 Basic Body Shapes To Choose Better Clothes
>>Ranking the 10 most used smart technology devices
>> Top 5+ Best E-readers: Compact & Convenient Pen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • WebStorm 2021.3 Crack + Keygen [Latest-2022]WebStorm 2021 Activation Code & Crack For Win/Mac WebStorm 2021.3 Crack Build 213.4293.8 is the one and only perfect Java editing tool that… Read More
  • Shapes 5.0 – Simple diagramming appby NMac Shapes is a simple, elegant diagramming app for OS X. Shapes gives you all of the most important features you need in a diagramming tool with… Read More
  • ForgeCert - "Golden" Certificates ForgeCert uses the BouncyCastle C# API and a stolen Certificate Authority (CA) certificate + private key to forge certificates for arbitrary users ca… Read More
  • IsoBuster 4.8 Crack Incl Keygen New Version 2022IsoBuster 2021 Crack With Key [Mac/Win] Torrent IsoBuster 4.8 Crack full version is the complete set of tools that deals only with optical discs plu… Read More
  • EaseUS Partition Master 16 Crack + License Code 2022EaseUS Partition Master 16 Crack Key + Keygen [32 & 64 Bit] EaseUS Partition Master 16 Crack is a windows-based program that offers an all-in-on… Read More
Newer Post Older Post Home

0 Comments:

Post a Comment


Copyright © 2025 Linchakin | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates