Using namespace to reference variables : NameSpace « Language « C++






Using namespace to reference variables

  
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
  int y = 10;
}

namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}

int main () {
  using namespace first;
  cout << x << endl;
  cout << y << endl;
  cout << second::y << endl;
  cout << second::x << endl;
  return 0;
}
  
    
  








Related examples in the same category

1.Namespace Demo: define a namespaceNamespace Demo: define a namespace
2.Namespaces are additiveNamespaces are additive
3.Demonstrate a namespaceDemonstrate a namespace
4.Some Namespace OptionsSome Namespace Options
5.A namespace can be nested within anotherA namespace can be nested within another
6.use explicit std:: qualification.use explicit std:: qualification.
7.Namespace code section
8.Use namespaces to wrap variables
9.Enclosure variables with namespace
10.Defines and tests namespaces.Defines and tests namespaces.