public member function
iter_type get_date ( iter_type s, iter_type end, ios_base& str,
ios_base::iostate& err, tm* t) const;
Parses the sequence of characters between s
for a date sequence, and stores its values into the tm
object pointed by t
The function extracts characters until the character extracted cannot be part of a valid date sequence expression or end
is reached. The next character in the sequence is pointed by the iterator returned by the function.
What constitutes a valid time sequence depends on the locale (it matches the 'x'
specifier in the strftime
C function). Generally, it is something similar to 01/01/01
If successful, the function may set any relevant members of the tm
. The remaining members are left unchanged.
The function updates err
with the error status if necessary:
If the sequence of characters cannot produce any valid value for the tm
according to its formatting rules, the function sets err
If the function exhausts the sequence of characters (i.e., it reaches end
) during its operations, ios_base::eofbit
is set in err
may be set by a single operation).
is set as err
's value, indicating success.
During its operation, the version of this function in the generic template simply calls the virtual protected member do_get_date
, which is the member function in charge of performing the actions described above.
- s, end
- Iterators pointing to the beginning and ending characters of the sequence. The range used is [s,end), which contains all the characters between s and end, including the character pointed by s but not the character pointed by end.
iter_type is a member alias of the second template parameter of time_get (i.e., the facet's iterator type).
- Object of a class derived from ios_base (generally an input stream object). It is used to obtain formatting information.
- Stream error state object, of type ios_base::iostate where the resulting state will be stored.
- Pointer to an object of type struct tm (see ctime), whose members may be set by a call to this member function.
The next character in the sequence right after where the extraction operation ended.
is a member alias of the second template parameter of time_get
(i.e., the facet's iterator type).
// time_get::get_date example
using namespace std;
int main ()
locale loc; // "C" locale
// get time_get facet:
const time_get<char>& tmget = use_facet <time_get<char> > (loc);
istringstream iss ("01/02/03");
istreambuf_iterator<char> itbegin (iss); // beginning of iss
istreambuf_iterator<char> itend; // end-of-stream
tmget.get_date (itbegin, itend, iss, state, &when);
cout << "year: " << when.tm_year << endl;
cout << "month: " << when.tm_mon << endl;
cout << "day: " << when.tm_mday << endl;
Notice that the date order
in the "C"
locale is mdy
and that in the tm_mon
member of tm
the first month (january) always has a value of 0
. A value of 3
represents the year 1903 (2003 is represented by 103
- Read time (public member function)
- Read weekday (public member function)
- Read month name (public member function)
- Write time (public member function)