0

In C++, since the namespace std contains the declaration of all standard library functions, then why do we need to include iostream header to use I/O functions. Can we not just write 'using namespace std' so that the compiler knows where to get the definition? I want to know the need for including a header file for using any feature like strings too if that function declaration is already present in std namespace.

  • 1
    Does this answer your question? [C++ namespace and include](https://stackoverflow.com/questions/389922/c-namespace-and-include) – mightyWOZ Jul 18 '21 at 07:52
  • Related question https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h Btw: `using namespace xyz;` has an effect entirely different to includes; it just changes the way you can refer to existing symbols. Even without `using namespace std;` you could refer to `cout` using the full name `std::cout`. If you're asking about why symbols are not available by default without an include: That was a design decision made when C was born... At that time the pcs were a lot less preformant than they're now. – fabian Jul 18 '21 at 08:08

1 Answers1

0

The compiler finds the declared namespace std in the included headers. It cannot know where to get the definition from unless you don't specify it by including libraries.

Caglayan DOKME
  • 948
  • 8
  • 21