strcpy、wcscpy、 |
您所在的位置:网站首页 › strcpy的原型 › strcpy、wcscpy、 |
strcpy, wcscpy, _mbscpy
项目
12/02/2022
复制字符串。 提供这些函数的更安全版本;请参阅 strcpy_s、wcscpy_s、_mbscpy_s。 重要 _mbscpy 无法用于在 Windows 运行时中执行的应用程序。 有关详细信息,请参阅通用 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 char *strcpy( char (&strDestination)[size], const char *strSource ); // C++ only template wchar_t *wcscpy( wchar_t (&strDestination)[size], const wchar_t *strSource ); // C++ only template unsigned char *_mbscpy( unsigned char (&strDestination)[size], const unsigned char *strSource ); // C++ only 参数strDestination 目标字符串。 strSource null 终止的源字符串。 返回值其中每个函数都会返回目标字符串。 没有保留任何返回值以指示错误。 注解strcpy 函数将 strSource(包括终止空字符)复制到 strDestination 指定的位置。 如果源和目标字符串重叠,则 strcpy 的行为是未定义的。 重要 由于 strcpy 不会在复制 strSource 前检查 strDestination 中空间是否足够,所以这可能会造成缓冲区溢出。 因此,建议改用 strcpy_s。 wcscpy 和 _mbscpy 分别是 strcpy 的宽字符和多字节字符版本。 参数和返回值为 wcscpy 宽字符字符串。 参数和返回值为 _mbscpy 多字节字符串。 否则这三个函数否则具有相同行为。 在 C++ 中,这些函数具有模板重载,以调用这些函数的更新、更安全副本。 有关详细信息,请参阅 安全模板重载。 默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。 一般文本例程映射 TCHAR.H 例程 _UNICODE 和 _MBCS 未定义 _MBCS 已定义 _UNICODE 已定义 _tcscpy strcpy _mbscpy wcscpy 要求 例程所返回的值 必需的标头 strcpy wcscpy 或 _mbscpy有关兼容性的详细信息,请参阅兼容性。 示例 // crt_strcpy.c // compile with: /W3 // This program uses strcpy // and strcat to build a phrase. #include #include 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 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |