How to print numbers with leading zeros in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip> 

int main() {
    int x = 12;

    std::cout << std::setw(5) << std::setfill('0') << x << "\n";
}



/*

run:

00012

*/

 



answered May 4, 2021 by avibootz

Related questions

...