DEV Community

Mehfila A Parkkulthil
Mehfila A Parkkulthil

Posted on

Day 10 : C++ Language | Strings | string concatenation

String Concatenation

Adding of two or more strings can be said as concatenation.
The + operator can be used between strings to add them together to make a new string .

To write a string , string library is must to add.
ie,#include <string>



#include <iostream>
#include <string>
using namespace std;

int main(){

   // string is a datatype and fname, lname and fullName are variables.

   string fname = "Mehfila ";
   string lname = " Parkkulthil";
   string fullName = fname + lname ;
   cout << fullName ;

   return 0;
}




//output: MehfilaParkkulthil

Enter fullscreen mode Exit fullscreen mode

To create a space between Mehfila and Parkkulthil in output , you need to add a space with double quotes "" or single quotes '' .



#include <iostream>
#include <string>
using namespace std;

int main(){

   // string is a datatype and fname, lname and fullName are variables.

   string fname = "Mehfila ";
   string lname = " Parkkulthil";
   string fullName = fname + " " + lname ;
   cout << fullName ;

   return 0;
}




//output: Mehfila Parkkulthil

Enter fullscreen mode Exit fullscreen mode

Previous Blogs

Top comments (0)