strcpy, wcscpy, _mbscpy
Copia una cadena.Versiones más seguras de estas funciones están disponibles; vea strcpy_s, wcscpy_s, _mbscpy_s.
Importante |
---|
_mbscpy no se puede utilizar en las aplicaciones que se ejecutan en Windows en tiempo de ejecución.Para obtener más información, vea Funciones CRT no compatibles con /ZW. |
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
Parámetros
strDestination
Cadena de destino.strSource
Cadena terminada en null de origen.
Valor devuelto
Cada una de estas funciones devuelve la cadena de destino.No se reserva ningún valor devuelto para indicar un error.
Comentarios
La función de strcpy copia strSource, incluido el carácter null de terminación, en la ubicación especificada por strDestination.El comportamiento de strcpy es indefinido si las cadenas de origen y de destino se superponen.
Nota sobre la seguridad |
---|
Dado que strcpy no comprueba el espacio suficiente en strDestination antes de copiar strSource, es una causa potencial de saturaciones del búfer.Por consiguiente, recomendamos usar strcpy_s en su lugar. |
wcscpy y _mbscpy son versiones, respectivamente, de carácter ancho y de multibyte- carácter de strcpy.Los argumentos y el valor devuelto de wcscpy son cadenas de caracteres; las de _mbscpy son cadenas de multibyte- carácter.Estas tres funciones se comportan exactamente igual de otra manera.
En C++, estas funciones tienen sobrecargas de plantilla que se invoque según el nuevo, garantiza que sus homólogos de estas funciones.Para obtener más información, vea Sobrecargas de plantilla de seguridad.
Asignaciones de la rutina de Genérico- texto
Rutina de TCHAR.H |
_UNICODE y _MBCS no definidos |
_MBCS definido |
_UNICODE definido |
---|---|---|---|
_tcscpy |
strcpy |
_mbscpy |
wcscpy |
Requisitos
Rutina |
Encabezado necesario |
---|---|
strcpy |
<string.h> |
wcscpy |
<string.h> o <wchar.h> |
_mbscpy |
<mbstring.h> |
Para obtener información adicional de compatibilidad, vea Compatibilidad.
Ejemplo
// 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 );
}
Equivalente en .NET Framework
Vea también
Referencia
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