std::strcpy
From cppreference.com
| ヘッダー <cstring> で定義 |
||
| char* strcpy( char* dest, const char* src ); |
||
srcが指す文字列を、ヌル終端文字を含めて、destが指す文字配列にコピーします。
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言語のドキュメント strcpy
| |