fork(85) download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. template<typename ... Args>
  6. string string_format(const string& format, Args ... args){
  7. size_t size = 1 + snprintf(nullptr, 0, format.c_str(), args ...);
  8. unique_ptr<char[]> buf(new char[size]);
  9. snprintf(buf.get(), size, format.c_str(), args ...);
  10. return string(buf.get(), buf.get() + size);
  11. }
  12.  
  13. int main() {
  14. //test the function here
  15. cout << string_format("%d", 202412);
  16. //<test>
  17. return 0;
  18. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
202412