Defined in header <iomanip> | ||||
---|---|---|---|---|
| (since C++11) |
When used in an expression in >> get_time(tmb, fmt)
, parses the character input as a date/time value according to format string fmt
according to the std::time_get
facet of the locale currently imbued in the output stream out
. The resultant value is stored in a std::tm
object pointed to by tmb
.
Parameters
tmb | - | valid pointer to the std::tm object where the result will be stored | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fmt | - | pointer to a null-terminated CharT string specifying the conversion format The format string consists of zero or more conversion specifiers, whitespace characters, and ordinary characters (except
Note: |
Return value
Returns an object of unspecified type such that if in
is the name of an input stream of type std::basic_istream<CharT, Traits>
, then the expression in >> get_time(tmb, fmt)
behaves as if the following code was executed:
typedef std::istreambuf_iterator<CharT, Traits> Iter;
typedef std::time_get<CharT, Iter> TimeGet;
std::ios_base::iostate err = std::ios_base::goodbit;
const TimeGet& tg = std::use_facet<TimeGet>(in.getloc());
tg.get(Iter(in.rdbuf()), Iter(), in, err, tmb, fmt, fmt + traits::length(fmt));
if (err != std::ios_base::goodbit)
in.setstate(err);
Notes
As specified in std::time_get::do_get
, which this function calls, it's unspecified if this function zero out the fields in *tmb
that are not set directly by the conversion specifiers that appear in fmt
: portable programs should initialize every field of *tmb
to zero before calling std::get_time
.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> #include <sstream> #include <locale> #include <iomanip> int main() { std:: tm t = {}; std::istringstream ss( "2011-Februar-18 23:12:34" ); ss.imbue(std::locale( "de_DE.utf-8" )); ss >> std::get_time(&t, "%Y-%b-%d %H:%M:%S" ); if (ss.fail()) { std::cout << "Parse failed\n" ; } else { std::cout << std::put_time(&t, "%c" ) << '\n' ; } } |
Output:
1 | Sun Feb 18 23:12:34 2011 |
See also
parses time/date values from an input character sequence into struct std::tm (class template) | |
(C++11) | formats and outputs a date/time value according to the specified format (function template) |
Please login to continue.