Why is std namespace required here?

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

If I delete the 2nd statement, the assembly will fail.

Why is this necessary?

+3
source share
3 answers

Since coutthey endlare contained inside the namespace std.

You can delete the line using namespace stdand put std::coutand instead std::endl.

Here is an example that should make namespaces clear:

Stuff.h:

namespace Peanuts
{
  struct Nut
  {
  };
}


namespace Hardware
{
  struct Nut
  {
  };
}

- using namespace Hardware, Nut . , , : 1) 2) using.

, .

, #include:

#include <iostream> cout endl. , std, iostream.

+12

cout std. , "std:: cout" , .

+2

cout cerr isotream, std:: cout std:: cerr

, , min max, , , std:: min std:: max. , , "afx" ATL.

"using" , , , "using std", , std:: , .
, mystuff, min() max(). std:: min() mystuff:: min(), , "using std" "using mystuff", , "c"

. , std:: cout, , regualr, cout, .

0

Source: https://habr.com/ru/post/1738361/


All Articles