Input and Output in C++

In this article, I will introduce you to the basic input and output standard in the C ++ programming language. In the C ++ programming language, the cin object is used to take input from the user, and the cout object is used to display the output to the user.

Before getting started with this tutorial if you don’t know how to use C++ in VS code studio you can learn to setup the VS code studio of the C++ programming language from here.

User Input and Standard Output in C++

In C ++, cout sends formatted output to standard output devices, such as the monitor. We use the cost object with the << operator to display the output.

The cin takes formatted inputs from standard input devices such as the keyboard. We use the cin object with the >> operator to take the inputs. Now let’s look at the example below:

using namespace std;

int main(){
    int amount1;
    cout<<"Amount given by dad :";

    int amount2;
    cout<<"Amount given by mom :";

    int sum = amount1+amount2;
    return 0;

Amount given by dad :5000
Amount given by mom :2000

As you can see in the above example, we are first taking the user input by using the cin statement and then printing the output by using by cout statement. You can frame as many as examples you want the process will remain the same, only the operations will change.

So this is how we can use the user input and standard output operations in the C++ programming language. Just never forget to include the <iostream> file and always mention that you are using the namespace std. This tells the compiler that you are using the namespace standard.

These very small things make C++ programming language as the best programming language as it forces you to learn how a computer performs calculations.

I hope you liked this article on the basic input and output standard in the C++ programming language. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1498

Leave a Reply