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 | ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
void* memset(void* dest,int ch,std::size_t count); | ||
Copies the valuestatic_cast<unsignedchar>(ch) into each of the firstcount characters of the object pointed to bydest. If the object is apotentially-overlapping subobject or is notTriviallyCopyable (e.g., scalar, C-compatible struct, or an array of trivially copyable type), the behavior is undefined. Ifcount is greater than the size of the object pointed to bydest, the behavior is undefined.
Contents |
dest | - | pointer to the object to fill |
ch | - | fill byte |
count | - | number of bytes to fill |
dest
std::memset
may be optimized away (under theas-if rules) if the object modified by this function is not accessed again for the rest of its lifetime (e.g.,gcc bug 8537). For that reason, this function cannot be used to scrub memory (e.g., to fill an array that stored a password with zeroes).
Solutions for that includestd::fill with volatile pointers,(C23)memset_explicit(),(C11)memset_s, FreeBSDexplicit_bzero or MicrosoftSecureZeroMemory
.
#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';}
Output:
00000011000000110000001100000011000000110000001100000011000000110000001100000011000000110000001100000011000000110000001100000011
copies one buffer to another (function)[edit] | |
moves one buffer to another (function)[edit] | |
copies the given wide character to every position in a wide character array (function)[edit] | |
copy-assigns the given value to every element in a range (function template)[edit] | |
copy-assigns the given value to N elements in a range (function template)[edit] | |
(C++11) | checks if a type is trivially copyable (class template)[edit] |
C documentation formemset |