Namespaces
Variants

std:: strcpy

From cppreference.net
ヘッダーで定義 <cstring>
char * strcpy ( char * dest, const char * src ) ;

src が指す文字列(ヌル終端文字を含む)を、 dest が指す先頭要素の文字配列にコピーします。

宛先配列が十分な大きさでない場合、動作は未定義です。文字列が重複している場合、動作は未定義です。

目次

パラメータ

dest - 書き込み先の文字配列へのポインタ
src - コピー元のヌル終端バイト文字列へのポインタ

戻り値

dest

#include <cstring>
#include <iostream>
#include <memory>
int main()
{
    const char* src = "Take the test.";
//  src[0] = 'M'; // can't modify string literal
    auto dst = std::make_unique<char[]>(std::strlen(src) + 1); // +1 for null terminator
    std::strcpy(dst.get(), src);
    dst[0] = 'M';
    std::cout << src << '\n' << dst.get() << '\n';
}

出力:

Take the test.
Make the test.

関連項目

指定された文字数をある文字列から別の文字列にコピーする
(関数)
あるバッファから別のバッファにコピーする
(関数)