????7??using???? ?? using??
???????using???? ?? using?? ??????????????????????г?????????????????????????
????using std::cout; //using????
????using namespace std; //using??
????7.1??using????(using declaration)
??????? using ??????????????????????????
????using ????????????? using ???????????????? using ??????????????β???????????????????????ж?????????屻???Ρ?
????using ??????????????????????????????? ?? ???????С?????????????using??????????????????
//using declaration in Global Scope
#include <iostream>
using std::cout;????????????????????????????//using????
using std::endl;????????????????????????????//using????
int main(void)
{
cout<<"Hello World"<<endl;
return 0;
}
//using declaration in Local Scope
#include <iostream>
void func(void)
{
using std::cout;
using std::endl;
cout << "Using Declarations In Function"<<endl;
}
int main()
{
func();
//  cout << "Hello" <<endl; //error: ‘cout’ and ‘endl’ were not declared in this scope
return 0;
}
//using declaration in Class Scope
#include <stdio.h>
class B
{
public:
void f(void) {printf("In B::f() ");}
void g(void) {printf("In B::g() ");}
};
class C
{
public:
void g() {printf("In C::g() ");};
};
class D : public B
{
public:
using B::f;      // OK: B is a base of D2
using B::g;      // OK: B is a base of D2
// using C::g;      // error: C isn't a base of D2
};
int main(void)
{
D MyD;
MyD.f();
MyD.g();
}
//using declaration in Namespce
#include <iostream>
namespace MyNames
{
using std::string;
using std::cout;
using std::endl;
string str;
void func(void){cout << "Hello"<<endl;}
}
int main(void)
{
MyNames::func();
return 0;
}
????7.2??using??(using directive)
????using ????????????????е??????????
????using ?????????????????????????? ?? ???????У????????????????????С?
//using directive in Global Scope
#include <iostream>
using namespace std;????????????????????????//using??
int main(void)
{
cout<<"Hello World"<<endl;
return 0;
}
//using directive in Local Scope
#include <iostream>
void func(void)
{
using namespace std;
cout << "Using Declarations In Function"<<endl;
}
int main()
{
func();
//  cout << "Hello" <<endl; //error: ‘cout’ and ‘endl’ were not declared in this scope
return 0;
}
//using declaration in Namespce
#include <iostream>
namespace MyNames
{
using namespace std;
string str;
void func(void){cout << "Hello"<<endl;}
}
int main(void)
{
MyNames::func();
//    cout<<"Hello"<<endl; //error: ‘cout’ and ‘endl’ were not declared in this scope
return 0;
}
????7.3?????????using??
????using ????????????????????????????????????????????????????ó???????????????? using ???????Щ???е??????????????????????????????????3????
??????????????? using ????????????????????????????????using ??????????????????????????????е???????????? using ???????????????????????????????
????8???????t???
////file : mynames.hpp
#ifndef MYNAMES__HPP_
#define MYNAMES__HPP_
namespace MyNames
{
//Member:Variable
extern int iVal;
//Member:Class
class MyString
{
public:
MyString(const std::string&);
void OutputString(void);
private:
std::string str;
};
//Member:Function
void NormalFunc(void);
//Member:Struct
struct st_Names
{
char ch;
int count;
};
//Member:Union
union un_Names
{
char ch;
int count;
};
//Member:enum
enum en_Names
{
ZERO??
ONE??
TWO
};
}
#endif /* MYNAMES__HPP_ */
//------------------------------------------------------------------------------------------------------------
//file : mynames.cpp
#include <iostream>
#include "mynames.hpp"
namespace MyNames
{
int iVal = 100;
MyString::MyString(const std::string& refstr)
{
str = refstr;
}
void MyString::OutputString(void)
{
std::cout << str << std::endl;
}
void NormalFunc(void)
{
std::cout << "NormalFunc" << std::endl;
}
}
//-------------------------------------------------------------------------------------------------------------
//file : example.cpp
#include <iostream>
#include "mynames.hpp"
namespace Name = MyNames;
using namespace Name;
int main(void)
{
std::cout<<iVal<<std::endl;
std::cout<<Name::iVal<<std::endl;
std::cout<<MyNames::iVal<<std::endl;
MyNames::MyString mystr("Hello");
mystr.OutputString();
MyNames::NormalFunc();
MyNames::st_Names myst;
myst.count = 0;
MyNames::en_Names myen;
myen = MyNames::ZERO;
MyNames::un_Names myun;
myun.count = 1;
return 0;
}