最終更新日時:
が更新

履歴 編集

function
<cstring>

std::strcpy

namespace std {
  char* strcpy(char* s1, const char* s2);
}

概要

文字列をコピーする。

効果

s2が指す文字列を、終端のヌル文字を含めてs1が指す配列へコピーする。

コピー元とコピー先の領域が重なっている場合、動作は未定義である。

戻り値

s1を返す。

備考

  • この関数は、フリースタンディング処理系でも使用できる。
  • コピー先s1が指す配列は、s2の文字列を終端のヌル文字まで格納できる十分な大きさを持っていなければならない。

#include <cstring>
#include <iostream>

int main()
{
  char dst[6];

  std::strcpy(dst, "hello");

  std::cout << dst << std::endl;
}

出力

hello

バージョン

言語

  • C++98

関連項目

  • strncpy: 文字列をコピーする(上限サイズ指定)
  • strcat: 文字列を結合する
  • strdup: 文字列を複製する

参照