Show time and date. : cout manipulator « Console « C++






Show time and date.

Show time and date.
 


#include <iostream>
#include <ctime>
using namespace std;

// A time and date output manipulator.
ostream &td(ostream &stream)
{
  struct tm *localt;
  time_t t;
  
  t = time(NULL);
  localt = localtime(&t);
  stream << asctime(localt) << endl;

  return stream;
}

int main()
{
  cout << td << '\n';

  return 0;
}


           
         
  








Related examples in the same category

1.Turn on hex output with uppercase X.Turn on hex output with uppercase X.
2.Skip 10 characters.Skip 10 characters.
3.Set cout format: ios::showposSet cout format: ios::showpos
4.Set cout format: ios::showpoint | ios::uppercase | ios::scientificSet cout format: ios::showpoint | ios::uppercase | ios::scientific
5.Predefine format for coutPredefine format for cout
6.Utility function for cinUtility function for cin
7.Define function to set coutDefine function to set cout
8.bell manipulator (using escape sequence \a)
9.ret manipulator (using escape sequence \r)
10.tab manipulator (using escape sequence \t)
11.endLine manipulator (using escape sequence \n and the flush member function)
12.Redirecting Standard Input And OutputRedirecting Standard Input And Output