Condividi tramite


strcpy, wcscpy, _mbscpy

Copia una stringa. Sono disponibili versioni più sicure di queste funzioni; vedere strcpy_s, wcscpy_s, _mbscpy_s.

Importante

_mbscpy non può essere utilizzato nelle applicazioni eseguite in Windows Runtime.Per ulteriori informazioni, vedere Funzioni CRT non supportate 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

Parametri

  • strDestination
    Stringa destinazione.

  • strSource
    Stringa di origine con terminazione null.

Valore restituito

Ognuna di queste funzioni restituisce la stringa di destinazione. Nessun valore restituito è riservato per indicare un errore.

Note

La funzione strcpy copia strSource, incluso il carattere di terminazione null, nella locazione specificata da strDestination. Il comportamento di strcpy non è definito se le stringhe di origine e di destinazione si sovrappongono.

Nota sulla sicurezzaNota sulla sicurezza

Poiché strcpy non verifica la presenza di spazio sufficiente in strDestination prima di eseguire la copia strSource, può essere causa di sovraccarichi del buffer.Di conseguenza, è consigliabile invece utilizzare strcpy_s.

wcscpy e _mbscpy sono rispettivamente versioni a caratteri estesi e a caratteri multibyte di strcpy. Gli argomenti e il valore restituito di wcscpy sono stringhe di caratteri di tipo "wide", quelli di _mbscpy sono stringhe di caratteri multibyte. Altrimenti queste tre funzioni si comportano in modo identico.

In C++, queste funzioni presentano overload dei modelli che richiamano le relative controparti sicure e più recenti. Per ulteriori informazioni, vedere Overload di modelli sicuri.

Mapping di routine su testo generico

Routine TCHAR.H

_UNICODE & _MBCS non definiti

_MBCS definito

_UNICODE definito

_tcscpy

strcpy

_mbscpy

wcscpy

Requisiti

Routine

Intestazione obbligatoria

strcpy

<string.h>

wcscpy

<string.h> o <wchar.h>

_mbscpy

<mbstring.h>

Per ulteriori informazioni sulla compatibilità, vedere Compatibilità.

Esempio

// 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 .NET Framework

System::String::Copy

Vedere anche

Riferimenti

Modifica di stringhe (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