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 180 views
1 answer 184 views
1 answer 168 views
1 answer 170 views
1 answer 178 views
1 answer 172 views
1 answer 192 views
...