D
D
DVoropaev2017-09-30 14:24:03
C++ / C#
DVoropaev, 2017-09-30 14:24:03

How to display numbers of the same length in C++?

cout << std::hex << " " << num;
It is necessary that 8 digits be output.
That is, the number f23a87 was displayed as 00f23a87

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2017-09-30
@0xD34F

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int num = 0xf23a87;
    cout << hex << setfill('0') << setw(8) << num;

    return 0;
}

D
devalone, 2017-09-30
@devalone

en.cppreference.com/w/cpp/io/manip/setfill

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question