std:: strcpy
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Null-terminated byte strings
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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.
関連項目
|
指定された文字数をある文字列から別の文字列にコピーする
(関数) |
|
|
あるバッファから別のバッファにコピーする
(関数) |
|
|
Cドキュメント
for
strcpy
|
|