In this tutorial you will learn about the C++ Program to Print String and its application with practical example.
C++ Program to Print String
In this tutorial, we will learn to create a C++ program that will Print String in C++ programming.
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ programming.
What is String?
A string is traditionally a sequence of characters, symbols. Every English letter used for input-output in any function is a string. The output messages are also a set of strings.
Algorithm to print string in the output:-
1. Declaring the variables for the program.
2. Taking the input from the user in character format.
3. Printing the data taken in input from the user in character format.
4. End program
Program to Print String
As we all know the string is a collection of characters in c++ programming. In c++ programming, we can take the input from the user in string format. In today’s program, we will take input in string format. The second will display the string with the help of a small program. The String is the most useful terminology in any programing language. For string manipulation in c++ programming, there are many predefined functions available.
With the help of this program, we can take input and Print String.
Program to Print String:-
/* C++ Program to Print String */
using namespace std;
/* variable definition and initialization for the program*/
//strary will store the string value for the input
/* Taking input from the user and assign it to a variable */
cout << "Please write something for something :" << endl;
//cin >> strary;
/* Printing the output for the string taken as a input */
cout << "You enter the string:"<< endl << strary << endl;
In the above program, we have first initialized the required variable.
- strary = it will hold the input string value from the user.
Taking Input from the user.
Printing the data in the output in the string format.
The Program Code for the main method.