Printing string concatenation in C++


This program is written in C++ and concatenates two string variables Name1 and Name2 to form a new string fullName using the + operator. The final concatenated string is then printed to the console using the cout statement. The program begins by including the necessary header files. The iostream header file is required for input/output operations, while the string.h header file is used for manipulating strings.

Next, the program defines three string variables Name1, Name2, and fullName. Name1 is initialized to the value "Tutor ", Name2 is initialized to the value "Joes", and fullName is initially empty. The two string variables Name1 and Name2 are then concatenated using the + operator and the result is stored in the fullName variable. Finally, the program prints the concatenated string fullName to the console using the cout statement with a newline character (\n) at the beginning to start the output on a new line.

Source Code

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string Name1 = "Tutor ";
    string Name2 = "Joes";
    string fullName = Name1+Name2;
    cout<<"\n"<<fullName;
    return 0;
}
To download raw file Click Here

Output

Tutor Joes


Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples