C++ Program to Print String

« Previous Program Next Program »

Print String in C++

To print a string in C++ programming, first ask to the user to enter any string (like his/her name) and receive the string using the function gets().

Now to print the string, just place the string after cout<< to print the string. Here, we print the string (your name) with Hello, as shown here in the following program.

C++ Programming Code to Print String

Following C++ program ask to the user to enter a string like your first name, then it will display your first name after Hello,:

/* C++ Program - Print String */
void main()
	char str[20];
	cout<<"Enter your first name : ";
	cout<<"Hello, "<<str;

When the above C++ program is compile and executed, it will produce the following result:

C++ program print string

Same Program in Other Language

You may like the same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test