std::strcpy
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cstring> で定義
|
||
char* strcpy( char* dest, const char* src ); |
||
src の指す文字列を、ヌル終端も含めて、 dest によって最初の要素が指されている文字配列にコピーします。
dest 配列が十分大きくない場合、動作は未定義です。 文字列がオーバーラップしている場合、動作は未定義です。
引数
| dest | - | 書き込む文字配列を指すポインタ |
| src | - | コピーするヌル終端バイト文字列を指すポインタ |
戻り値
dest。
例
Run this code
#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.
関連項目
| 文字列から別の文字列へ文字を一定量コピーします (関数) | |
| バッファを別のバッファへコピーします (関数) | |
strcpy の C言語リファレンス
| |