Getting Inputs in C++ Programming


The program is a C++ program that demonstrates the use of different data types and input/output operations. The program is currently commented out, which means that all the statements are disabled, except for one that reads a line of text from the user. Let's break down the program line by line:

  • #include<iostream>: This line is a preprocessor directive that includes the iostream library, which provides the cout and cin objects used to output and input data to/from the console.
  • using namespace std;: This line declares that we want to use the std namespace.
  • int main(): This is the main function of the program.
  • {: The opening curly brace marks the beginning of the main function.
  • string a;: This line declares a string variable a.
  • cout<<"\nEnter The Para : ";: This line outputs the text "Enter The Para : " to the console.
  • getline(cin,a);: This line reads a line of text from the user and stores it in the variable a.
  • cout<<a;: This line outputs the value of the a variable to the console.
  • return 0;: This line returns an integer value of 0 to the operating system, indicating that the program has executed successfully.
  • }: The closing curly brace marks the end of the main function.

The current program is commented out, which means that all the statements are disabled except for one that reads a line of text from the user. This line uses the getline() function to read a line of text from the user and store it in the a variable. The getline() function is used to read an entire line of text, whereas the cin object is used to read only a single word or number. Finally, the program outputs the value of the a variable to the console.

Source Code

#include<iostream>
using namespace std;
int main()
{
    //int a,b;
    /*
    float a,b;
    cout<<"Enter The Integer Value : "<<endl;
    cin>>a>>b;
    cout<<"Total is :"<<a+b;
 
    char a;
    char a;
    cout<<"\nEnter The Character : ";
    cin>>a;
    cout<<"Character is : "<<a;
 
    string a;
 
    cout<<"\nEnter The String : ";
    cin>>a;
    cout<<a;*/
    string a;
    cout<<"\nEnter The Para : ";
    getline(cin,a);
    cout<<a;
 
    return 0;
}
 

Output

Enter The Integer Value :
23
456
Total is :479

Enter The Character : S
Character is : S

Enter The String : Tutor Joes
Tutor

Enter The Para : Tutor Joes Computer Education
Tutor Joes Computer Education
To download raw file Click Here

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