namespace std {
char* strcpy(char* s1, const char* s2);
}
概要
文字列をコピーする。
効果
s2が指す文字列を、終端のヌル文字を含めてs1が指す配列へコピーする。
コピー元とコピー先の領域が重なっている場合、動作は未定義である。
戻り値
s1を返す。
備考
- この関数は、フリースタンディング処理系でも使用できる。
- コピー先
s1が指す配列は、s2の文字列を終端のヌル文字まで格納できる十分な大きさを持っていなければならない。
例
#include <cstring>
#include <iostream>
int main()
{
char dst[6];
std::strcpy(dst, "hello");
std::cout << dst << std::endl;
}
出力
hello
バージョン
言語
- C++98
関連項目
参照
- P2338R4 Freestanding Library: Character primitives and the C library
- C++26で、この関数がフリースタンディング処理系で使用可能になった