Using "using" statements...

Posted on 2003-03-30
Medium Priority
Last Modified: 2010-04-01
1) I noticed that a lot of people are using the File 2 version... Why? (I know why namespace exists in the langauge, so you don't need to explain about that).
2) What is the different between #include <iostream.h> and #include <iostream>?

// File 1
#include <iostream.h>

int main()
  cout << "Hello" << endl;
  return 0;

// File 2
#include <iostream>

using std::cout;
using std::endl;

int main()
  cout << "Hello" << endl;
  return 0;
Question by:chaos_hooi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 30

Accepted Solution

Axter earned 100 total points
ID: 8236087
<iostream.h> is NOT part of the C++ standard, where as <iostream> is part of the C++ standard.

The *.h version is included in most compilers for backward compatibility.

You should avoid using the *.h version, and use the extensionless version.

Since the *.h version is not part of the standard, it can, and is different from one compiler to the next.

Expert Comment

ID: 8237014
From the thread title I guess you are interested in why there is 'using std::cout;' as opposed to 'using namespace std;'. It is sort of a compromise between the ugly and dangerous std::-namespace resolution into global namespace and reduced typing. It only brings those symbols that you actually plan on using into global namespace and is favoured over the 'using namespace ...;', yet I don't use either on, as this causes potential ambiguities. As a matter of personal taste I believe that 'std::cout << ...' is easier to read than 'using std::cout; cout << ...', but opinios differ on this one.


Author Comment

ID: 8243329

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question