c++ namespace example

Example 1: using namespace std in c++

#include 

using namespace std;

int main()
{
    cout << "Hello World";
    system("pause");
    return 0;
    
}

Example 2: what is namespace in c++

//namespace is a declarative region to provide scope for identifiers
#include 

using namespace std; //including namespace std for cin and cout
//my custom namespace for variables and functions
namespace abc
{
  void fun()
  {
    cout<<"Hello world"<

Example 3: c++ namespace example

#include 
using namespace std;
namespace square{
	int x;
	int y;
}
int main(){
	using namespace square;
	x = 10;
	y = 0;
	cout << x << y << endl;
}

Example 4: namespace c++

Namespace std::cout or cout <<

Example 5: access the namespace members using namespace member function

namespace Parent
{
    inline namespace new_ns
    {
         template 
         struct C
         {
             T member;
         };
    }
     template<>
     class C {};
}

Tags:

Misc Example