다음을 통해 공유


strcpy, wcscpy, _mbscpy

문자열을 복사합니다. 이러한 기능의 더 안전한 버전을 사용할 수 있습니다. strcpy_s, wcscpy_s, _mbscpy_s를 참조하십시오.

중요

_mbscpy는 Windows 런타임에서 실행되는 응용 프로그램에서 사용할 수 없습니다.자세한 내용은 /ZW에서 지원하지 않는 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 함수는 strDestination에 의해 지정된 위치에서 null 종결 문자를 포함하는 strSource를 복사합니다. 원본 영역과 대상 문자열이 겹치면 strcpy 동작이 지정되지 않습니다.

보안 정보보안 정보

다음 strcpy 가 strDestination 내에서 strSource 를 복사하기 전에 충분한 공간을 확인하지 않기 때문에, 버퍼 오버런이 발생할 수 있습니다.따라서, strcpy_s 를 대신에 사용하는 것이 좋습니다.

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

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

제네릭 텍스트 라우팅 매핑

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 );
}
  

해당 .NET Framework 항목

System::String::Copy

참고 항목

참조

문자열 조작(CRT)

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