在线文档教程
C++
本土化 | Localizations

std::time_get::do_get_weekday

STD:时间[医]GET::GET[医]工作日,性病::时间[医]得到::做[医]弄到[医]平日

Defined in header
public: iter_type get_weekday( iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const;(1)
protected: virtual iter_type do_get_weekday( iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const;(2)

1%29公共成员函数,调用受保护的虚拟成员函数。do_get_weekday最派生的类。

2%29从序列中读取连续字符。[beg, end)并使用此区域设置所期望的工作日默认格式,解析工作日名称%28(可能缩写为%29),该格式与"%a"函数所使用的std::get_time,,,time_get::get,以及POSIX函数strptime()

如果它找到缩写的名称,后面跟着对全名有效的字符,它将继续读取,直到它使用全名的所有字符或找到一个期望的字符%27T。在这种情况下,即使前几个字符是有效的缩写,解析也会失败。

解析的工作日存储在std::tm场域t->tm_wday...

如果在读取有效的工作日名称之前到达了结束迭代器,则函数设置。std::ios_base::eofbiterr如果遇到解析错误,则函数将std::ios_base::failbiterr...

参数

beg-iterator designating the start of the sequence to parse
end-one past the end iterator for the sequence to parse
str-a stream object that this function uses to obtain locale facets when needed, e.g. std::ctype to skip whitespace or std::collate to compare strings
err-stream error flags object that is modified by this function to indicate errors
t-pointer to the std::tm object that will hold the result of this function call

返回值

中的最后一个字符[beg, end)这被确认为有效周名的一部分。

注记

这个函数通常不区分大小写.

如果遇到解析错误,则此函数的大多数实现将离开。*t未经修改。

二次

#include <iostream> #include <locale> #include <sstream> #include <iterator> void try_get_wday(const std::string& s) { std::cout << "Parsing the weekday out of '" << s << "' in the locale " << std::locale().name() << '\n'; std::istringstream str(s std::ios_base::iostate err = std::ios_base::goodbit; std::tm t; std::istreambuf_iterator<char> ret = std::use_facet<std::time_get<char>>(str.getloc()).get_weekday( std::istreambuf_iterator<char>(str), std::istreambuf_iterator<char>(), str, err, &t str.setstate(err if(str) { std::cout << "Successfully parsed, weekday number is " << t.tm_wday; if(ret != std::istreambuf_iterator<char>()) { std::cout << " Remaining content: "; std::copy(ret, std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(std::cout) } else { std::cout << " the input was fully consumed"; } } else { std::cout << "Parse failed. Unparsed string: "; std::copy(ret, std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(std::cout) } std::cout << '\n'; } int main() { std::locale::global(std::locale("lt_LT.utf8") try_get_wday("Št" try_get_wday("Šeštadienis" std::locale::global(std::locale("en_US.utf8") try_get_wday("SATELLITE" std::locale::global(std::locale("ja_JP.utf8") try_get_wday("土曜日" }

二次

产出:

二次

Parsing the weekday out of 'Št' in the locale lt_LT.utf8 Successfully parsed, weekday number is 6 the input was fully consumed Parsing the weekday out of 'Šeštadienis' in the locale lt_LT.utf8 Successfully parsed, weekday number is 6 the input was fully consumed Parsing the weekday out of 'SATELLITE' in the locale en_US.utf8 Successfully parsed, weekday number is 6 Remaining content: ELLITE Parsing the weekday out of '土曜日' in the locale ja_JP.utf8 Successfully parsed, weekday number is 6 the input was fully consumed

二次

另见

get_time (C++11)parses a date/time value of specified format (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/locale/time[医]得到/得到[医]平日