How to Show Your Output in C++

·

2 min read

Hello and Welcome, My name is Ammar and today I will be showing how you can print anything on a screen.

First of all, On the first line, we type -

#include<iostream>

This is a standard input-output stream. It offers input and output functions. On the second line, we type -

using namespace std;

This is a standard library for which we can use names and objects. It makes our job a lot easier when we type out code. Now let me show you the whole code -

#include<iostream> 
using namespace std;
int main(){
    cout<<"Coding with Ammar"; // Outputs on terminal
}

Now you may be wondering what is this "int main()". "int main()" defines the entry or the starting point of the C++ program code. Any code that is situated in this is executed.

On the fourth line, you may now see the start of our code the cout function. In the cout function, the c means character and out means output. It will output any variable or string through this. The operator "<<" means that we are somewhat like transferring data from the string to the function. Oh and don't worry if you do not know what a string is I will cover it in my future post.

So the output of the above program will be - "Coding with Ammar".

Lastly always don't forget to add a semi-colon(;) at the end of each line in C++. I have seen many developers including myself losing our minds while finding an error in our code just to find out that a semi-colon is missing :(

You can also watch my YouTube video on this -