Really simple question but sometimes I've seen the word Padding used and always wondered what it really meant. For example if I had a string and what ever the input was I wanted to pad it to 32 characters, what does that mean?
Edit: and padding of output strings (which is prob what you were asking about in the first place?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <iomanip>
usingnamespace std;
int main(){
int x = 12;
cout << "x = " << x << " (no padding)\n"
<< setfill('0') // fill char is space by default
<< "x = " << setw(8) << x << " (padded with leading 0s)\n"
<< left // numbers are right aligned by default
<< "x = " << setw(8) << x << " (padded with trailing 0s)\n";
return 0;
}
x = 12 (no padding)
x = 00000012 (padded with leading 0s)
x = 12000000 (padded with trailing 0s)
Also...
In the C++ (and C) case, the term padding usually turns up in connection with memory alignment of data structures.
But it can also turn up in connection with cryptography and hashing, when an algorithm requires data to have a size which is a multiple of some block size. For example, AES has a block size of 8 bytes, so input data has to be padded to a multiple of 8 bytes before encrypting with this alogorithm.