`zfill` in C++
This post was written more than 12 years ago. Some of it may be out of date.
Here is a function in C++ that works like Python's zfill. It is convenient when you want to generate folder names or similar values with zero-padded serial numbers.
std::string zfill(const std::string& str, const int width)
{
std::stringstream ss;
ss << std::setw(width) << std::setfill('0') << str;
return ss.str();
}