名前空間
変種
操作

std::strcpy

提供: cppreference.com
< cpp‎ | string‎ | byte
ヘッダ <cstring> で定義
char* strcpy( char* dest, const char* src );

src の指す文字列を、ヌル終端も含めて、 dest によって最初の要素が指されている文字配列にコピーします。

dest 配列が十分大きくない場合、動作は未定義です。 文字列がオーバーラップしている場合、動作は未定義です。

目次

[編集] 引数

dest - 書き込む文字配列を指すポインタ
src - コピーするヌル終端バイト文字列を指すポインタ

[編集] 戻り値

dest

[編集]

#include <iostream>
#include <cstring>
#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 the null terminator
    std::strcpy(dst.get(), src);
    dst[0] = 'M';
    std::cout << src << '\n' << dst.get() << '\n';
}

出力:

Take the test.
Make the test.

[編集] 関連項目

文字列から別の文字列へ文字を一定量コピーします
(関数) [edit]
バッファを別のバッファへコピーします
(関数) [edit]