How to format an integer with zero-padding in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip> // std::setw // std::setfill

int main() {
    int number = 319;

    // Format the integer with zero padding (e.g., 6 digits)
    std::cout << std::setfill('0') << std::setw(6) << number << std::endl;
}



/*
run:

000319

*/

 



answered Jun 18, 2025 by avibootz

Related questions

1 answer 57 views
1 answer 83 views
1 answer 79 views
1 answer 74 views
1 answer 84 views
1 answer 75 views
1 answer 85 views
...