A namespace is a declarative region that provides a scope to the
identifiers (the names of types, functions, variables, etc) inside
it. Namespaces are used to organize code into logical groups and to
prevent name collisions that can occur especially when your code base
includes multiple libraries
//using namespaces
using namespace std;
//creating namespaces
namespace custom{
class example{
public:
static int method(){
return 0;
}
};
};
//using custom namespaces
using namespace custom;
#include <iostream>
using namespace std;
int main() {
cout<< "Hello World" ;
}
//If you are a web developer, please give https://code.ionicbyte.com/ a try
//Namespaces provide a method for preventing name conflicts in large projects.
//Symbols declared inside a namespace block are placed in a named scope that
//prevents them from being mistaken for identically-named symbols in other
//scopes. Multiple namespace blocks with the same name are allowed.
//All declarations within those blocks are declared in the named scope.
namespace yourName{
//any code you want to put inside
}
#include <iostream>
using namespace std;
namespace square{
int x;
int y;
}
int main(){
using namespace square;
x = 10;
y = 0;
cout << x << y << endl;
}
Namespaces avoids name collisions bacause of large libraray in c++.
This feature was not supported in C
Namespace std::cout or cout <<