strcpy, wcscpy, _mbscpy

문자열을 복사합니다. 이러한 함수의 더 안전한 버전을 사용할 수 있습니다. 를 _mbscpy_swcscpy_s참조하세요.strcpy_s

Important

Windows 런타임에서 실행되는 애플리케이션에서는 _mbscpy를 사용할 수 없습니다. 자세한 내용은 유니버설 Windows 플랫폼 앱에서 지원되지 않는 CRT 함수를 참조하세요.

구문

char *strcpy(
   char *strDestination,
   const char *strSource
);
wchar_t *wcscpy(
   wchar_t *strDestination,
   const wchar_t *strSource
);
unsigned char *_mbscpy(
   unsigned char *strDestination,
   const unsigned char *strSource
);
template <size_t size>
char *strcpy(
   char (&strDestination)[size],
   const char *strSource
); // C++ only
template <size_t size>
wchar_t *wcscpy(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource
); // C++ only
template <size_t size>
unsigned char *_mbscpy(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource
); // C++ only

매개 변수

strDestination
대상 문자열입니다.

strSource
Null 종료 소스 문자열입니다.

반환 값

이러한 각 함수는 대상 문자열을 반환합니다. 반환 값 없음은 오류를 나타내는 데 예약되어 있습니다.

설명

strcpy 함수는 null 종료 문자를 포함하여 strSourcestrDestination에 지정된 위치로 복사합니다. 소스 문자열과 대상 문자열이 겹치는 경우 strcpy의 동작이 정의되지 않습니다.

Important

strcpystrSource를 복사하기 전에 strDestination의 공간이 충분한지 확인하지 않으므로 버퍼 오버런의 잠재적 원인이 될 수 있습니다. 따라서 대신 사용하는 strcpy_s 것이 좋습니다.

wcscpy_mbscpy는 각각 strcpy의 와이드 문자 및 멀티바이트 문자 버전입니다. 인수 및 반환 값 wcscpy 은 와이드 문자열입니다. 인수 및 반환 값 _mbscpy 은 멀티바이트 문자열입니다. 그렇지 않으면 이들 세 함수는 동일하게 작동합니다.

C++에서 이러한 함수는 보다 최신의 보안 대응 함수를 호출하는 템플릿 오버로드를 갖고 있습니다. 자세한 내용은 보안 템플릿 오버로드를 참조 하세요.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

일반 텍스트 루틴 매핑

TCHAR.H 루틴 _UNICODE 정의 _MBCS 되지 않음 _MBCS 정의 _UNICODE 정의
_tcscpy strcpy _mbscpy wcscpy

요구 사항

루틴에서 반환된 값 필수 헤더
strcpy <string.h>
wcscpy <string.h> 또는 <wchar.h>
_mbscpy <mbstring.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

// crt_strcpy.c
// compile with: /W3
// This program uses strcpy
// and strcat to build a phrase.

#include <string.h>
#include <stdio.h>

int main( void )
{
   char string[80];

   // If you change the previous line to
   //   char string[20];
   // strcpy and strcat will happily overrun the string
   // buffer.  See the examples for strncpy and strncat
   // for safer string handling.

   strcpy( string, "Hello world from " ); // C4996
   // Note: strcpy is deprecated; use strcpy_s instead
   strcat( string, "strcpy " );           // C4996
   // Note: strcat is deprecated; use strcat_s instead
   strcat( string, "and " );              // C4996
   strcat( string, "strcat!" );           // C4996
   printf( "String = %s\n", string );
}
String = Hello world from strcpy and strcat!

참고 항목

문자열 조작
strcat, wcscat, _mbscat
strcmp, wcscmp, _mbscmp
strncat, _strncat_l, wcsncat, _wcsncat_l, _mbsncat, _mbsncat_l
strncmp, wcsncmp, _mbsncmp, _mbsncmp_l
strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l
_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l
strrchr, wcsrchr, _mbsrchr, _mbsrchr_l
strspn, wcsspn, _mbsspn, _mbsspn_l