- cstring[meta header]
- std[meta namespace]
- function[meta id-type]
namespace std {
void* memcpy(void* s1, const void* s2, size_t n);
}- size_t[link /reference/cstddef/size_t.md]
メモリデータをコピーする。
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;
}- std::memcpy[color ff0000]
hello
- C++98
- P2338R4 Freestanding Library: Character primitives and the C library
- C++26で、この関数がフリースタンディング処理系で使用可能になった