Console Output in C++

The command used for outputting text to console is the ‘cout’ statement. It resides in the iostream.h header file within the std namespace. For now ignore the terms and just get familiar with the program below.

Here is a simple program that outputs data to the console.

#include <iostream>
using namespace std;

int main() {

// cout is an output stream, that represents the standart output stream

// “<<” operator is known as “insertion operator”

// is outputs data to the stream

cout << ”A string”;

// to insert a newline, output manipulator endl

cout << endl;

// or one can combine those two outputs in one line of code

cout << ”Another string” << endl;

// one can output a number in a similar way

cout << ”Number: “ << 7 << endl;

int data = 9;

cout << “The data variable contains the value: ” << data << endl;

return 0;
}

Output of the Above Program would be

A string
Another string
Number: 7
The data variable contains the value 9

Advertisement

About Ali Turab Gilani
BS Computer Sciences from G.C University Lahore. Served as Teaching Assistant for Programming Fundamentals... Vice President IEEE Society Student Chapter...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.