Programming Language/C/C++

[C/C++] error C4996: 'strcpy' 'strcat' 오류 해결

깐요 2017. 4. 21. 13:25

error C4996

cstring을 지시한 후 strcpy(), strcat()을 사용할 때 다음과 같은 컴파일 오류가 생길 수 있다


error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.


이러한 에러가 발생하는 이유는 함수가 다른 설정 이름을 갖거나 안전하지 않은 경우, 변형이 있는 경우, 구식인 경우다

오류 메세지를 보면 사용되지 않는 함수 또는 전역 변수를 대체할 수 있는 safe_version 항목을 제안해준다

strcpy_s, strcat_s가 그 예시이다

따라서 strcpy_s(), strcat_s() 를 사용하면 오류가 해결된다


또는 헤더 파일 코드 상단에 

#define _CRT_SECURE_NO_WARNINGS

을 추가해주면 된다


MSDN: https://msdn.microsoft.com/ko-kr/library/ttcz0bys.aspx

320x100