C++ Userinput


Go to main Page

Userinput in C++

In this tutorial, we are going to learn about basic input and output.

C++ Input

For user input we use cin.

We use the cin object along with the >> operator for taking input.

#include<iostream>
        using namespace std;
        int main()
        {
            int age;
            cout<<"Please enter Your age";
            cin>>age;
        }

Output in C++

For Output we use cout to display output on the screen.

#include<iostream>
        using namespace std;
        int main()
        {
            int age;
            cout<<"Please enter Your age";
            cin>>age;
            cout<<"Your age is "<<age;
        }

C++ Multiple Inputs

#include <iostream>
using namespace std;

int main() {
    char a;
    int num;

    cout << "Enter a character and an integer: ";
    cin >> a >> num;

    cout << "Character: " << a << endl;
    cout << "Number: " << num;

    return 0;
}


Output

Enter a character and an integer: F
23
Character: F
Number: 23