I’m trying to write a program that generates a hex number based on a given number of digits. For instance, say that the user inputs 3, I want to generate a hex number of 0x000 and store it in some variable. Another example, say the user inputs 4 the hex number to be generated will be 0x0000.
Any ideas?
Thanks in advance.
>Solution :
0x0, 0x00, 0x000 and so on, when stored in a variable, all have the same effect.
What you want to do is to store the desired number of digits in a separate variable and apply that configuration when selecting a representation of the value (be it 0 or otherwise) in output.
For doing that in C++, I recommend the formatting features provided as described e.g. here:
https://en.cppreference.com/w/cpp/io/manip/setw
and at the links you find on that page as "See also".