c++中实现python中的zfill()函数的功能
该博客主要介绍了使用c++的库函数来实现python中的zfill()的功能.也就是对一个整数的前方进行补零实现对齐:
源代码:
#include <iomanip>
#include <sstream>
#include <iostream>
std::string format_int(int n, int numberOfLeadingZeros = 0){
std::ostringstream s;
s << std::setw(numberOfLeadingZeros) << std::setfill('0') << n;
return s.str();
}