public member function
<locale>
std::time_get::get_monthname
iter_type get_monthname ( iter_type s, iter_type end, ios_base& str,
ios_base::iostate& err, tm* t) const;
Read month name
Parses the sequence of characters between
s and
end for the name of a month, and stores its value into the
tm object pointed by
t.
The function extracts characters until the character extracted cannot be part of a valid month name or
end is reached. The next character in the sequence is pointed by the iterator returned by the function.
What constitutes a valid name of a month, or whether abbreviations are accepted, depends on the locale (it matches the
'b' or
'B' specifiers in the
strftime C function).
If successful, the function may set any relevant members of the
tm structure
t (generally,
tm_mon). 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 struct
t according to its formatting rules, the function sets
err to
ios_base::failbit.
If the function exhausts the sequence of characters (i.e., it reaches
end) during its operations,
ios_base::eofbit is set in
err (both
failbit and
eofbit may be set by a single operation).
Otherwise,
ios_base::goodbit 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_monthname, which is the member function in charge of performing the actions described above.
Parameters
- 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).
- str
- Object of a class derived from ios_base (generally an input stream object). It is used to obtain formatting information.
- err
- Stream error state object, of type ios_base::iostate where the resulting state will be stored.
- t
- Pointer to an object of type struct tm (see ctime), whose members may be set by a call to this member function.
Return value
The next character in the sequence right after where the extraction operation ended.
iter_type is a member alias of the second template parameter of
time_get (i.e., the facet's iterator type).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// time_get::get_monthname example
#include <iostream>
#include <sstream>
#include <locale>
using namespace std;
int main ()
{
locale loc; // "C" locale
// get time_get facet:
const time_get<char>& tmget = use_facet <time_get<char> > (loc);
ios::iostate state;
istringstream iss ("August");
istreambuf_iterator<char> itbegin (iss); // beginning of iss
istreambuf_iterator<char> itend; // end-of-stream
tm when;
tmget.get_monthname (itbegin, itend, iss, state, &when);
cout << "month: " << (when.tm_mon + 1) << endl;
return 0;
}
|
Output:
See also
- time_get::get_time
- Read time (public member function)
- time_get::get_date
- Read date (public member function)
- time_get::get_weekday
- Read weekday (public member function)
- time_put::put
- Write time (public member function)