Printing to the standard output using cout<< C++ program sample


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Printing to the standard output using cout<< in C++ programming

To show: How to print (write) to the standard input in C++ programming using cout




// some of the cout usage

#include <iostream>

using namespace std;


void main(void)


int q, s = 0, t = 0;


q = 10*(s + t);

cout<<"Enter 2 integer numbers,"

" separated by a space: ";



q = 10*(s + t);


// using '\n' for newline. The single quote (') or double quotes (") does not matter?

cout<<"simple math calculation, just for demo"<<'\n';

// using endl for new line

cout<<"q = 10(s + t) = "<<q<<endl<<endl;

cout<<"That all folks!!"<<"\n";

cout<<"Study the source code and the output\n";



Output example:


Enter 2 integer numbers, separated by a space: 77 88

simple math calculation, just for demo

q = 10(s + t) = 1650


That all folks!!

Study the source code and the output

Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index