fork download
  1. #include <iostream>
  2.  
  3. constexpr const char* format_of(char) { return "%c"; }
  4. constexpr const char* format_of(int) { return "%d"; }
  5. constexpr const char* format_of(unsigned long) { return "%lu"; }
  6. constexpr const char* format_of(unsigned long long) { return "%llu"; }
  7.  
  8. template <typename T>
  9. void my_printf(T t)
  10. {
  11. printf(format_of(t), t);
  12. printf(" with format '%s'\n", format_of(t));
  13. }
  14.  
  15. int main() {
  16. my_printf('*');
  17. my_printf(42);
  18. my_printf(4242LLU);
  19. }
  20.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
* with format '%c'
42 with format '%d'
4242 with format '%llu'