public member function
<locale>
std::time_get::get (1)iter_type get (iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t, char format, char modifier=0) const;(2)
iter_type get (iter_type s, iter_type end, ios_base& str, ios_base::iostate& err, tm* t, const char_type* fmt_begin, const char_type* fmt_end) const;
Read time and date
Parses the sequence of characters between s and end for a sequence with the format of time and/or date specified by format (or by the sequence between fmt_begin and fmt_end), and stores the obtained values into the tm object pointed by t.The function reads characters until the character read cannot be part of a valid sequence in the format or end is reached. The next character after the last one processed by the function is pointed by the iterator returned by the function.
If successful, the function sets the relevant members of the tm structure t. The remaining members are left unchanged.
'%'
) followed by argument format, with modifier optionally inserted in between (when not equal to zero).
[fmt_begin,fmt_end)
sequentially and interprets them in the same way scanf treats its format string, except that the format specifiers recognized by the function are those used by strftime instead. For each sequence of characters that would be recognized as an specifier for strftime, the virtual protected member do_get is called with the proper arguments.
[fmt_begin,fmt_end)
was processed without reaching end. failbit Failure: The sequence did not match the expected format. eofbit end was reached:
[s,end)
, which contains all the characters between s and end, including the character pointed by s but not the character pointed by end.
<ctime>
), whose members are set by a successful call to this member function.
0
('\0'
) is interpreted as no modifier.
[s,end)
right after the last character used by the operation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// time_get::get example
#include <iostream> // std::cout, std::ios
#include <string> // std::string
#include <sstream> // std::istringstream
#include <ctime> // std::tm
#include <locale> // std::locale, std::time_get, std::use_facet
int main ()
{
std::locale loc; // classic "C" locale
// get time_get facet:
auto& tmget = std::use_facet <std::time_get<char> > (loc);
std::ios::iostate state;
std::istringstream iss ("year:2013 month:09 day:10");
std::string format ("year:%Y month:%m day:%d");
std::tm when;
tmget.get (iss, std::time_get<char>::iter_type(), iss, state, &when,
format.data(), format.data()+format.length() );
std::cout << "year: " << when.tm_year << '\n';
std::cout << "mon: " << when.tm_mon << '\n';
std::cout << "mday: " << when.tm_mday << '\n';
return 0;
}
year: 113 mon: 8 mday: 10
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4