C++ Program to Read a String with Spaces and Display it on Console

In this program, we will read a string with spaces using gets() function. The puts() function is used to display the entered string.

The function gets() : Reads characters from the standard input and stores them as a string. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.

The function puts() : prints characters from the standard output.

The cin>>) function reads a single word (without spaces), however gets() reads a line of string (with spaces)

Source Code
using namespace std;

int main()
    char name[30];
    cout<<"Enter the line of text: ";
    cout<<"\nYou entered the text....\n";
    return 0;
Enter the line of text: Welcome to the world of C++ Programming!

You entered the text....
Welcome to the world of C++ Programming!

"Coding Hub - Learn to code" app now available on Google Play Store