- memset function
- Fill a character by byte
- Inside the header file.
<cstring>
- Fill function
- Assigns the element of an interval to the same value according to the unit assignment value
- Inside the header file.
<algorithm>
- Because the Memset function is populated by bytes, the general memset can only be used to populate the char array (since only char is a byte) if the int array is filled, except for 0 and-1, the others cannot. Because only 00000000 = 0,-1 Similarly, if we fill each bit with "1", it will result in filling into "11111111"
- The fill function can be assigned any value, and the method of use is particularly simple:
- Fill (arr, arr + N, content to be filled in);
- For example:
#include <cstdio><algorithm>usingnamespace std; int Main () { int arr[]; Ten 2 ); return 0 ;}
- Vectors can also:
#include <algorithm>#include<vector>#include<iostream>using namespacestd;intmain () {vector<int> v{0,1,2,3,4,5,6,7,8,9}; Fill (V.begin (), V.end (),-1); return 0;}
- The way to use memset is:
#include <iostream><cstring>usingnamespace std; int Main () { int a[]; 0 sizeof a); return 0 ;}
"C + +" Fill function, the difference between fill and memset function