using namespace c++ code example

Example 1: using namespace std in c++

#include <iostream>

using namespace std;

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

Example 2: c++ custom namespace

//using namespaces
using namespace std;

//creating namespaces
namespace custom{
  class example{
    public:
    	static int method(){
          return 0;
        }
  };
};

//using custom namespaces
using namespace custom;

Example 3: c++ namespace example

#include <iostream>
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 <<

Tags:

Cpp Example