fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string number_to_string_with_nulls(int n)
  5. {
  6. char raw[32] = {};
  7. snprintf(raw, 32, "%08d", n);
  8. return raw;
  9. }
  10.  
  11.  
  12. int main() {
  13. std::cout << number_to_string_with_nulls(0) << std::endl;
  14. std::cout << number_to_string_with_nulls(12) << std::endl;
  15. std::cout << number_to_string_with_nulls(1024) << std::endl;
  16. std::cout << number_to_string_with_nulls(99999999) << std::endl;
  17. std::cout << number_to_string_with_nulls(999999991) << std::endl;
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
00000000
00000012
00001024
99999999
999999991