Did the namespaces exist prior to the introduction of the C++ 98 standard?

562 Views Asked by At

I read this page. C++ header files with no extension And I understood that comment as saying that namespaces existed even before the introduction of the C++ standard. So wasn't that comment saying that namespaces and the absence of file extension are not related? However, the following comment didn't mention how namespaces were used when using cout in iostream.h.

So my Questions are:

  1. Did the namespace really exist prior to the introduction of the C++ 98 standard?
  2. If it is true, how namespaces were used when using cout in iostream.h?
2

There are 2 best solutions below

0
Jerry Coffin On BEST ANSWER

The committee voted to accept namespaces into the standard in 1993. Most compilers supported it fairly shortly after that, so for around 5 years before the standard was approved.

Headers without extensions happened around the same time, so mostly when you used iostream.h, you just used cout << foo;, and when you switched to iostream, you used std::cout << foo;.

For backward compatibility, many compilers continued to supply an iostream.h for a while after they had iostream. It was often something like this:

#include <iostream>
using namespace std;

This was enough for a lot of fairly simple programs to compile, but broke with some that got into the dark corners of the older library code (and honestly, not even very dark corners).

Other compilers had two completely separate libraries though, so iostream.h contained declarations for one and iostream for the other.

1
Lemonina On

namespace concept was introduced to C++ in the 90s but the features and syntax were refined in C++98 standard

note that iostream.h header file isn't part of the C++ standard library -- it was used by early versions of Borland compiler for MS-DOS and has been deprecated for the standard <iostream> header

cout object is defined in the std namespace in the standard <iostream> header => that's why to use it you have to either:

  • qualify with prefix
std::cout
  • or bring the std namespace into scope
namespace std;