Ad Code

Why we use :"using namespace std"?

Why we use :"using namespace std"?


Namespaces allows us to group a set of global classes, objects and/or functions under a name. If you specify using namespace std then you don't have to put std:: throughout your code. The program will know to look in the std library to find the object. Namespace std contains all the classes, objects and functions of the standard C++ library.

Without namespace
Code:
#include <iostream>

int main () {
  std::cout << "Hello world!\n";
  return 0;
}


With namespace
Code:
#include <iostream>
using namespace std;

int main () {
  cout << "Hello world!\n";
  return 0;
}
Reactions

Post a Comment

0 Comments