| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Floating-point formatting | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| Integer formatting | |||||||||||||||||||||||||||||||
| Boolean formatting | |||||||||||||||||||||||||||||||
| Field width and fill control | |||||||||||||||||||||||||||||||
| Other formatting | |||||||||||||||||||||||||||||||
| Whitespace processing | |||||||||||||||||||||||||||||||
| Output flushing | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
| Status flags manipulation | |||||||||||||||||||||||||||||||
| Time and money I/O | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| Quoted manipulator | |||||||||||||||||||||||||||||||
(C++14) | |||||||||||||||||||||||||||||||
Defined in header <iomanip> | ||
template<class CharT> /*unspecified*/ get_time(std::tm* tmb,const CharT* fmt); | (since C++11) | |
When used in an expressionin>> get_time(tmb, fmt), parses the character input as a date/time value according to format stringfmt according to thestd::time_get facet of the locale currently imbued in the input streamin. The resultant value is stored in astd::tm object pointed to bytmb.
Contents |
| tmb | - | valid pointer to thestd::tm object where the result will be stored | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt | - | pointer to a null-terminatedCharT string specifying the conversion formatThe format string consists of zero or more conversion specifiers, whitespace characters, and ordinary characters (except
Note: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
An object of unspecified type such that
where the functionf is defined as:
template<class CharT,class Traits>void f(std::basic_ios<CharT, Traits>& str,std::tm* tmb,const CharT* fmt){using Iter=std::istreambuf_iterator<CharT, Traits>;using TimeGet= time_get<CharT, Iter>; std::ios_base::iostate err=std::ios_base::goodbit;const TimeGet& tg=std::use_facet<TimeGet>(str.getloc()); tg.get(Iter(str.rdbuf()), Iter(), str, err, tmb, fmt, fmt+ Traits::length(fmt)); if(err!=std::ios_base::goodbit) str.setstate(err);}
As specified instd::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 infmt: portable programs should initialize every field of*tmb to zero before callingstd::get_time.
Note: choose clang or gcc >= 12.1 to observe the output. libstdc++ before 12.1 does not correctly implement the%b specifier:bug #78714.
#include <iomanip>#include <iostream>#include <locale>#include <sstream> 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";elsestd::cout<<std::put_time(&t,"%c")<<'\n';}
Possible output:
Sun Feb 18 23:12:34 2011
| parses time/date values from an input character sequence intostd::tm (class template)[edit] | |
(C++11) | formats and outputs a date/time value according to the specified format (function template)[edit] |
(C++20) | parses achrono object from a stream(function template)[edit] |