전처리기는 빌드 들어가기 전에 시작함. 
멀티 플랫폼 소프트웨어를 개발할 때 사용. 
메크로를 이용해서 조건에 따른 컴파일을 하는 것을 배움.

main.cpp 

#include <iostream>
#include <algorithm>//max사용 
using namespace std;

#define MAX(a,b) (((a)>(b))?(a):(b)) //메크로
void doSomething();

int main()
{
doSomething();

//cout << MAX(1,20) << endl;
//cout << max(1 + 3,2) << endl; //include <algorithm>에 있음 

return 0;
}

*메크로: 코드를 다음 것으로 바꾸는 것 (주로 대문자로 씀) -> 최근에는 function을 더 많이 사용.

source.cpp

#include  <iostream>
using namespace std;

#define LIKE_APPLE //body가 있는 곳에 정의해야 적용됨. 

void doSomething()
{
#ifdef LIKE_APPLE
cout << "Apple" << endl;
#else
LIKE_APPLE //not defined
cout << "Orange" << endl;
#endif
}

'programming > c++' 카테고리의 다른 글

2.5 부동소수점 수  (0) 2019.04.11
2.1 기본 자료형 소개  (0) 2019.04.10
1.13 네임 스페이스 (명칭 공간)  (0) 2019.04.03
1.12 헤더가드  (0) 2019.04.03
1.11 헤더 파일 만들기  (0) 2019.04.01
Posted by 도이(doi)
,