Share via


time_get::get_time

Parses a string as the date produced by the X specifier for strftime.

iter_type get_time( 
   iter_type _First,  
   iter_type _Last, 
   ios_base& _Iosbase,  
   ios_base::iostate& _State,  
   tm* _Pt 
) const;

Parameters

  • _First
    Input iterator addressing the beginning of the sequence to be converted.

  • _Last
    Input iterator addressing the end of the sequence to be converted.

  • _Iosbase
    Unused.

  • _State
    Sets the appropriate bitmask elements for the stream state according to whether the operations succeeded.

  • _Pt
    A pointer to where the date information is to be stored.

Return Value

An input iterator addressing the first element beyond the input field.

Remarks

The member function returns do_get_time(_First, _Last, _Iosbase, _State, _Pt).

Example

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

   pszGetF << "11:13:20";
   pszGetF.imbue( loc );
   basic_istream<char>::_Iter i = use_facet 
      <time_get <char> >
      (loc).get_time(basic_istream<char>::_Iter(pszGetF.rdbuf( )),
               basic_istream<char>::_Iter(0), pszGetF, st, &t);

   if (st & ios_base::failbit)
      cout << "time_get::get_time("<< pszGetF.rdbuf( )->str( )<< ") FAILED on char: " << *i << endl;
   else

      cout << "time_get::get_time("<< pszGetF.rdbuf( )->str( )<< ") ="
      << "\ntm_sec: " << t.tm_sec
      << "\ntm_min: " << t.tm_min
      << "\ntm_hour: " << t.tm_hour
      << endl;
}
time_get::get_time(11:13:20) =
tm_sec: 20
tm_min: 13
tm_hour: 11

Requirements

Header: <locale>

Namespace: std

See Also

Reference

time_get Class