2

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?
busbug
  • 89
  • 4
  • There wasn't a standard... so it is kind of like chicken and egg situation. I know that the Watcom C++ compiler had namespace support from version 9.5 on (first version with C++ / 1994), even though I started using that in 1996. (https://en.wikipedia.org/wiki/Watcom_C/C%2B%2B) – Pepijn Kramer Apr 13 '23 at 04:17
  • 1
    Also see : [iostream-in-borland-c-compiler](https://stackoverflow.com/questions/51434007/iostream-in-borland-c-compiler) – Pepijn Kramer Apr 13 '23 at 04:18
  • C++ did not begin the journey toward standardization until the early 90s. https://en.cppreference.com/w/cpp/language/history – paddy Apr 13 '23 at 04:19
  • @molbdnilo I see. – Jason Apr 13 '23 at 04:45

2 Answers2

5

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
1

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;
Lemonina
  • 712
  • 2
  • 14
  • 2
    Re: "used by early versions of Borland compiler" -- literally true, but misleading; `` came from Cfront, the original Bell Labs implementation of C++. And, formally, `` was not deprecated; it never existed in the C++ standard. "Deprecated" means that something is supported in the current version of the standard, but might be removed in the future. – Pete Becker Apr 13 '23 at 13:11