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

std::memset

Defined in header <cstring>

void* memset( void* dest, int ch, std::size_t count );

转换值chunsigned char并将其复制到第一个count指向的对象的字符dest如果对象不是微不足道的-复制%28e。g.、标量、数组或与C兼容的结构%29,行为未定义.。如果count值所指向的对象的大小。dest,该行为是未定义的。

参数

dest

-

pointer to the object to fill

ch

-

fill byte

count

-

number of bytes to fill

返回值

dest...

注记

std::memset在如-规则%29,如果该函数修改的对象在其生命周期的剩余时间内未再次被访问,则为%28例如。gcc bug 853729%。因此,此函数不能用于清除内存%28例如。若要填充存储密码的数组,请使用0%29。解决方案包括C11memset_s、FreeBSD显式[医]b零或者微软SecureZeroMemory...

二次

代码语言:javascript
复制
#include <iostream>
#include <cstring>
 
int main()
{
    int a[20];
    std::memset(a, 0, sizeof a);
    for (int ai : a) std::cout << ai;
}

二次

产出:

二次

代码语言:javascript
复制
00000000000000000000

二次

另见

memcpy

copies one buffer to another (function)

memmove

moves one buffer to another (function)

wmemset

copies the given wide character to every position in a wide character array (function)

fill

copy-assigns the given value to every element in a range (function template)

fill_n

copy-assigns the given value to N elements in a range (function template)

is_trivially_copyable (C++11)

checks if a type is trivially copyable (class template)

C.memset的文档

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

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

扫码关注腾讯云开发者

领取腾讯云代金券