Printing string append in C++


This C++ code defines three strings Name1, Name2, and fullName. It then appends Name2 to Name1 using the append() method and stores the result in fullName. Finally, it prints out the value of fullName using cout.

Here's a step-by-step breakdown of what happens in the code:

  • The iostream and string.h headers are included to allow input and output and to use strings respectively.
  • The using namespace std; statement is included to avoid having to use std:: before all standard library functions and types.
  • Two strings are defined, Name1 and Name2, initialized with "Tutor " and "Joes" respectively.
  • The append() method is called on Name1 with Name2 as its argument, concatenating Name2 to the end of Name1. The result is stored in fullName.
  • The value of fullName is printed to the console using cout.
  • The main() function returns 0, indicating successful completion.

Source Code

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string Name1 = "Tutor ";
    string Name2 = "Joes";
    string fullName = Name1.append(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