Click on the banner to return to the class reference home page.

time_put


time_put_base time_put locale::facet

Summary

Time formatting facet for output.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <locale>
template <class charT, class OutputIterator = 
          ostreambuf_iterator<charT> >
class time_put;

Description

The time_put facet provides facilities for formatted output of date/time values. The member function of time_put take a date/time in the form of a struct tm and translate this into character string representation.

Interface

template <class charT, class OutputIterator =    
          ostreambuf_iterator<charT> >
class time_put : public locale::facet {
public:
  typedef charT            char_type;
  typedef OutputIterator   iter_type;
  explicit time_put(size_t = 0);
  iter_type put(iter_type, ios_base&, 
                char_type, const tm*,
                const charT*, const charT*) const;
  iter_type put(iter_type, ios_base&, char_type,
                const tm*, char, char = 0) const;
  static locale::id id;
protected:
  ~time_put();  // virtual
  virtual iter_type do_put(iter_type, ios_base&, 
                           char_type, const tm*,
                           char, char) const;
}; 

Types

char_type
iter_type




Constructors and Destructors

explicit time_put(size_t refs = 0)




~time_put();  // virtual and protected




Facet ID

static locale::id id;




Public Member Functions

iter_type 
put(iter_type s, ios_base& f, 
    char_type fill, const tm* tmb,
    const charT* pattern, const charT* pat_end) const;




iter_type 
put(iter_type s, ios_base& f, char_type fill,
    const tm* tmb, char format, char modifier = 0) const;




Protected Member Functions

virtual iter_type 
do_put(iter_type s, ios_base&, 
       char_type fill, const tm* t,
       char format, char modifier) const;

Example

// 
// timeput.cpp
//
#include <iostream>

int main ()
{
  using namespace std;

  typedef ostreambuf_iterator<char,char_traits<char> > iter_type;
  
  locale loc;
  time_t tm = time(NULL);
  struct tm* tmb = localtime(&tm);
  struct tm timeb;
  memcpy(&timeb,tmb,sizeof(struct tm));
  char pat[] = "%c";

  // Get a time_put facet
  const time_put<char,iter_type>& tp = 
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  use_facet<time_put<char,iter_type> >(loc);
#else
  use_facet(loc,(time_put<char,iter_type>*)0);
#endif

  // Construct a ostreambuf_iterator on cout
  iter_type begin(cout);
  
  cout << " --> ";
  tp.put(begin,cout,' ',&timeb,pat,pat+2);
 
  cout << endl << " --> ";
  tp.put(begin,cout,' ',&timeb,'c',' ');

  cout <<  endl;

  return 0;
}

See Also

locale, facets, time_get


©Copyright 1996, Rogue Wave Software, Inc.