fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iterator>
  4. #include <locale>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. class timefmt
  10. {
  11. public:
  12. timefmt(std::string fmt)
  13. : format(fmt) { }
  14.  
  15. friend ostream& operator <<(ostream &, timefmt const &);
  16.  
  17. private:
  18. string format;
  19. };
  20.  
  21.  
  22. std::ostream& operator <<(std::ostream& os, timefmt const& mt)
  23. {
  24. std::ostream::sentry s(os);
  25.  
  26. if (s)
  27. {
  28. time_t t = time(0);
  29. tm const* tm = localtime(&t);
  30. ostreambuf_iterator<char> out(os);
  31.  
  32. use_facet<time_put<char>>(os.getloc())
  33. .put(out, os, os.fill(),
  34. tm, &mt.format[0], &mt.format[0] + mt.format.size());
  35. }
  36.  
  37. os.width(0);
  38.  
  39. return os;
  40. }
  41.  
  42. int main() {}
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty