프로그래밍/Windows
tchar.h
즉흥
2014. 5. 13. 00:38
728x90
반응형
1 2 3 4 5 6 7 | #include<tchar.h> #include<Windows.h> #include<stdio.h> int main(){ _tprintf("T E S T "); return 0; } |
옛날에 위처럼 코딩하고 왜 _tprintf가 안 되지? 라고 생각했었던 때가 있었다.
_tprintf는
1 2 3 4 5 | #ifdef _UNICODE #define _tprintf wprintf #else #define _tprintf printf #endif |
라고 정의 되어 있는데 왜 안 될까..
이유는 바로 비쥬얼 스튜디오에서 사용자의 편의를 위해 기본적으로 _UNICODE를 정의해놨기 때문이였다.
따라서 _tprintf는 자동으로 wprintf로 바뀌었고, 그 인자는 유니코드 기반을 받기 때문에 안 됐던 것!
1 2 3 4 5 6 7 8 | #undef _UNICODE #include<tchar.h> #include<Windows.h> #include<stdio.h> int main(){ _tprintf("T E S T "); return 0; } |
#undef를 사용해서 _UNICODE를 제거하거나
1 2 3 4 5 6 7 | #include<tchar.h> #include<Windows.h> #include<stdio.h> int main(){ _tprintf(_T("T E S T ")); return 0; } |
_T()를 사용하면 된다 ^오^
1 2 | #define _T(x) __T(x) #define _TEXT(x) __T(x) |
728x90
반응형