首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::memmove

Defined in header <cstring>

void* memmove( void* dest, const void* src, std::size_t count );

复制件count指向的对象中的字符src指向的对象dest两个对象都被重新解释为unsigned char...

对象可能重叠:复制就像将字符复制到临时字符数组,然后将字符从数组复制到dest...

如果对象不是TriviallyCopyable的行为memmove未指定,并且可能没有定义...

参数

dest

-

pointer to the memory location to copy to

src

-

pointer to the memory location to copy from

count

-

number of bytes to copy

返回值

dest...

注记

尽管指定了“似乎”使用了临时缓冲区,但该函数的实际实现不会引起双重复制或额外内存的开销。为小count,它可以加载和写出寄存器;对于较大的块,一个常见的方法是将字节从缓冲区的开头向前复制,如果目标在源之前启动,则从末尾向后复制字节,否则返回到std::memcpy当完全没有重叠的时候。

二次

代码语言:javascript
复制
#include <iostream>
#include <cstring>
 
int main()
{
    char str[] = "1234567890";
    std::cout << str << '\n';
    std::memmove(str + 4, str + 3, 3); // copies from [4, 5, 6] to [5, 6, 7]
    std::cout << str << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
1234567890
1234456890

二次

另见

memcpy

copies one buffer to another (function)

memset

fills a buffer with a character (function)

wmemmove

copies a certain amount of wide characters between two, possibly overlapping, arrays (function)

copycopy_if (C++11)

copies a range of elements to a new location (function template)

copy_backward

copies a range of elements in backwards order (function template)

is_trivially_copyable (C++11)

checks if a type is trivially copyable (class template)

c备忘录文件

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券