본문 바로가기
Programming/C++

[c++] UsingNamespace

by OKOK 2017. 5. 11.

#include<iostream>


namespace Hybrid

{

void HybFunc(void)

{

std::cout<< "So simple Func" << std::endl;

std::cout << "In namespace Hybrid" << std::endl;

}

}


int main(void)

{

using Hybrid::HybFunc;

HybFunc();

return 0;

}



* using 사용 이유 namespace 의 생략을 위해서.. 귀찮음..

다만 원래 namespace 의 기능인 함수 이름 겹침을 유의할 필요성이 생김...



#include<iostream>


using std::cin;

using std::cout;

using std::endl;


int main(void) {

int num = 20;

cout << "Hello World!" << endl;

cout << "Hello " << "World!" << endl;

cout << num << ' ' << 'A';

cout << ' ' << 3.14 << endl;


return 0;

}


* cin, cout, endl 사용시 namespace 인 std 를 생략하겠습니다. 효율성을 위해서...


#include<iostream>


using namespace std;


int main(void) {

int num = 20;

cout << "Hello World!" << endl;

cout << "Hello " << "World!" << endl;

cout << num << ' ' << 'A';

cout << ' ' << 3.14 << endl;


return 0;

}



* using namespace std 는 std 라는 namespace 내부에 있는 함수를 사용시 std namespace를 삭제하도록 하겠습니다. :: 은 집합의 포함 관계라는 것을 연상하기...