I can give this one-line solution if you want a field of n_zero zeros:
auto new_str = std::string(n_zero - std::min(n_zero, old_str.length()), '0') + old_str;
For example, for std::string old_str = "45"; size_t n_zero = 4; you get new_str == "0045".