Printing basic example using String in C++


This is a simple C++ program that prompts the user to enter their name, reads the name from the console, and then displays the name back to the user.

  • The program uses the string class from the C++ Standard Library to store the name entered by the user.
  • In the main function, the program first declares a variable Name of type string. It then prompts the user to enter their name using the cout object to print the message to the console, and reads the input from the user using the cin object and stores it in the Name variable.
  • Finally, the program uses the cout object again to print a message that includes the name entered by the user.

Source Code

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string Name;
    cout<<"\nEnter your Name: ";
    cin>>Name;
    cout<<"\nYour name is "<<Name;
}
To download raw file Click Here

Output

Enter your Name: TUTORJOES
Your name is TUTORJOES


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