GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::strcpy - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cstring
  3. strcpy

最終更新日時: 2026年08月18日 02時34分25秒 (JST)
Akira Takahashi が更新

履歴 編集

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: 文字列を複製する

参照

  • P2338R4 Freestanding Library: Character primitives and the C library
    • C++26で、この関数がフリースタンディング処理系で使用可能になった
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.