クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
Visual Studio 2005
Visual Studio ドキュメント
Visual C++
リファレンス
ライブラリ リファレンス
ランタイム ライブラリ
 strcpy、wcscpy、_mbscpy

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
ランタイム ライブラリ リファレンス
strcpy、wcscpy、_mbscpy

文字列をコピーします。セキュリティが強化されたバージョンが使用可能になったので、これらの関数は使用されなくなりました。「strcpy_s、wcscpy_s、_mbscpy_s」を参照してください。

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 文字を含めて、strSource を、strDestination で指定された位置にコピーします。コピー元とコピー先の文字列が重なり合っている場合の strcpy 関数の動作は未定義です。

Security noteセキュリティに関するメモ :

strcpy は、strSource をコピーする前に strDestination に十分な領域があるかどうかを確認しないため、バッファ オーバーランが発生する可能性があります。代わりに、strcpy_s の使用を検討してください。

wcscpy 関数と _mbscpy 関数は、strcpy 関数のワイド文字バージョンとマルチバイト文字バージョンです。wcscpy 関数の引数と戻り値はワイド文字列で、_mbscpy 関数の引数と戻り値はマルチバイト文字列です。それ以外では、これらの関数の動作は同じです。

C++ では、これらの関数にテンプレートのオーバーロードがあります。このオーバーロードは、これらの関数に対応するセキュリティで保護された新しい関数を呼び出します。詳細については、「セキュリティ保護されたテンプレート オーバーロード」を参照してください。

汎用テキスト ルーチンのマップ
TCHAR.H のルーチン _UNICODE および _MBCS が未定義の場合 _MBCS が定義されている場合 _UNICODE が定義されている場合

_tcscpy

strcpy

_mbscpy

wcscpy

ルーチン 必須ヘッダー 互換性

strcpy

<string.h>

ANSI、Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition、Windows NT 4.0、Windows 2000、Windows XP Home Edition、Windows XP Professional、Windows Server 2003

wcscpy

<string.h> または <wchar.h>

ANSI、Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition、Windows NT 4.0、Windows 2000、Windows XP Home Edition、Windows XP Professional、Windows Server 2003

_mbscpy

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition、Windows NT 4.0、Windows 2000、Windows XP Home Edition、Windows XP Professional、Windows Server 2003

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

// 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];

   // Note that 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; consider using strcpy_s instead
   strcat( string, "strcpy " );           // C4996
   // Note: strcat is deprecated; consider using strcat_s instead
   strcat( string, "and " );              // C4996
   strcat( string, "strcat!" );           // C4996
   printf( "String = %s\n", string );
}

出力

String = Hello world from strcpy and strcat!
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker