std:: memset
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstring>
|
||
|
void
*
memset
(
void
*
dest,
int
ch,
std::
size_t
count
)
;
|
||
将值 static_cast < unsigned char > ( ch ) 复制到由 dest 指向的对象的前 count 个字符中。若该对象是 可能重叠的子对象 或非 可平凡复制 (例如标量、C兼容结构体或可平凡复制类型的数组),则行为未定义。若 count 大于 dest 所指向对象的大小,则行为未定义。
目录参数
返回值dest 注释
针对此问题的解决方案包括使用
std::fill
配合volatile指针、
(C23)
memset_explicit()
、
(C11)
memset_s
、FreeBSD的
explicit_bzero
或微软的
示例
运行此代码
#include <bitset> #include <climits> #include <cstring> #include <iostream> int main() { int a[4]; using bits = std::bitset<sizeof(int) * CHAR_BIT>; std::memset(a, 0b1111'0000'0011, sizeof a); for (int ai : a) std::cout << bits(ai) << '\n'; } 输出: 00000011000000110000001100000011 00000011000000110000001100000011 00000011000000110000001100000011 00000011000000110000001100000011 参阅
| |||||||||||||||||||||||||||