namespace

Explain the meaning of iostream namespace with code;

Not the full code:

//#include<iostream>
/*using namespace std;//If you don't write this
//iostream does not introduce standard std for header files, which requires programmers to write manually
intmain()
{
	// Then you must write std::cout<<.....
	cout<<"namespace test"<<endl;
	return 0;
} */


//define the namespace
namespace namespaceA
{
	int a=10;
}
namespace namespaceB
{
	int a=20;
	namespace namespaceC
	{
		struct Teacher
		{
			char name[32];
			int age;
		};
	}
}


// use namespace
intmain()
{
	using namespace namespaceA;
	using namespace namespaceB;
	cout<<namespaceA::a<<endl;
	cout<<namespaceB::a<<endl;
	
	//Displayed full write; (1)
//	namespaceB::namespaceC::Teacher t1;
	//t1.age=33;
	
	//(2) has the same effect as one;
	using namespaceB::namespaceC::Teacher;
	Teacher t2;
	t2.age=36;
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325731775&siteId=291194637