본문 바로가기

C++/기초

[C++] namespace

namespace

  • 변수나 함수 충돌 방지
  • 영역 접근 연산자 :: 사용
    • ex : Aspace::test(); , Bspace::test();
#include <stdio.h>
#include <iostream>
#include <iomanip>

using namespace std;
/* using을 통해 프로그램 전체에 사용할 수 있음
 * 이를 이용하여 std::cout을 cout으로 사용
*/
namespace test {
	void func_1() {
    // 네임스페이스 test안에 함수func_1 선언 
		cout << "call func_1" << endl;
	}
}


void main() {
	test::func_1();
    //네임스페이스 test의 func_1함수 실행
}

result

 

namespace std iostream iomanip
역할 표준 입출력 조정 문자