namespace std {
void* memcpy(void* s1, const void* s2, size_t n);
}
概要
メモリデータをコピーする。
効果
s2が指すオブジェクトからs1が指すオブジェクトへ、先頭nバイトをコピーする。
コピー元とコピー先の領域が重なっている場合、動作は未定義である。領域が重なりうる場合はmemmoveを使用する。
戻り値
s1を返す。
備考
- この関数は、フリースタンディング処理系でも使用できる。
例
#include <cstring>
#include <iostream>
int main()
{
const char src[] = "hello";
char dst[6] = {};
// 終端ヌル文字を含めてコピーする
std::memcpy(dst, src, sizeof(src));
std::cout << dst << std::endl;
}
出力
hello
バージョン
言語
- C++98
関連項目
参照
- P2338R4 Freestanding Library: Character primitives and the C library
- C++26で、この関数がフリースタンディング処理系で使用可能になった