Compartilhar via


time_put::put

Outputs time and date information as a sequence of CharTypes.

iter_type put( 
   iter_type _Next,  
   ios_base& _Iosbase, 
   char_type _Fill,  
   const tm* _Pt,  
   char _Fmt,  
   char _Mod = 0 
) const; 
iter_type put( 
   iter_type _Next,  
   ios_base& _Iosbase, 
   char_type _Fill,  
   const tm* _Pt, 
   const CharType* _First,  
   const CharType* _Last 
) const;

Parameters

Return Value

An iterator to the first position after the last element inserted.

Remarks

The first member function returns do_put(_Next, _Iosbase, _Fill, _Pt, _Fmt, _Mod). The second member function copies to *_Next ++ any element in the interval [_First, _Last) other than a percent (%). For a percent followed by a character C in the interval [_First, _Last), the function instead evaluates _Next = do_put(_Next, _Iosbase, _Fill, _Pt, C, 0) and skips past C. If, however, C is a qualifier character from the set EOQ#, followed by a character C2 in the interval [_First, _Last), the function instead evaluates _Next = do_put(_Next, _Iosbase, _Fill, _Pt, C2, C) and skips past C2.

Example

// time_put_put.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <sstream>
#include <time.h>
using namespace std;
int main( )
{
   locale loc;
   basic_stringstream<char> pszPutI;
   ios_base::iostate st = 0;
   struct tm t;
   memset( &t, 0, sizeof( struct tm ) );

   t.tm_hour = 5;
   t.tm_min = 30;
   t.tm_sec = 40;
   t.tm_year = 00;
   t.tm_mday = 4;
   t.tm_mon = 6;

   pszPutI.imbue( loc );
   char *pattern = "x: %X %x";
   use_facet <time_put <char> >
   (loc).put(basic_ostream<char>::_Iter(pszPutI.rdbuf( )),
          pszPutI, ' ', &t, pattern, pattern+strlen(pattern));

      cout << "num_put( ) = " << pszPutI.rdbuf( )->str( ) << endl;

      char strftimebuf[255];
      strftime(&strftimebuf[0], 255, pattern, &t);
      cout << "strftime( ) = " << &strftimebuf[0] << endl;
}
num_put( ) = x: 05:30:40 07/04/00
strftime( ) = x: 05:30:40 07/04/00

Requirements

Header: <locale>

Namespace: std

See Also

Reference

time_put Class