The C++ namespace: explicitly using the 'using namespace std' C++ program example


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

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: Using the C++ standard  namespace statement explicitly in C++ programming

To show: How  to use the 'using namespace std' explicitly in C++ programming




// using C++ standard namespace

#include <iostream>

// but has to explicitly use the 'using namespace std'

using namespace std;


// another way of simplifying type identifier

typedef unsigned short USHORT;


// function prototype

USHORT FindTheArea(USHORT length, USHORT width);


int main(void)


USHORT lengthOfYard;

USHORT widthOfYard;

USHORT areaOfYard;


cout<< "\nThe wide of your yard(meter)? ";

cin>> widthOfYard;

cout<< "\nThe long of your yard(meter)? ";

cin>> lengthOfYard;

areaOfYard = FindTheArea(lengthOfYard, widthOfYard);

cout<< "\nYour yard is ";

cout<< areaOfYard;

cout<< " square meter\n\n";


return 0;





return (l * w);



Output example:


The wide of your yard(meter)? 20

The long of your yard(meter)? 10

Your yard is 200 square meter

Press any key to continue . . .



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