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

std::time_get::get_monthname

STD:时间[医]GET::GET[医]月份名称,STD::时间[医]得到::做[医]弄到[医]月名

Defined in header
public: iter_type get_monthname( 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_monthname( iter_type beg, iter_type end, std::ios_base& str, std::ios_base::iostate& err, std::tm* t) const;(2)

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

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

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

解析的月份存储在std::tm场域t->tm_mon...

如果在读取有效的月份名称之前到达了结束迭代器,则函数将设置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> #include <ctime> void try_get_mon(const std::string& s) { std::cout << "Parsing the month 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_monthname( std::istreambuf_iterator<char>(str), std::istreambuf_iterator<char>(), str, err, &t str.setstate(err if(str) { std::cout << "Successfully parsed, month number is " << t.tm_mon; 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("ja_JP.utf8") try_get_mon("2月" std::locale::global(std::locale("th_TH.utf8") try_get_mon("กุมภาพันธ์" std::locale::global(std::locale("el_GR.utf8") try_get_mon("Φεβ" try_get_mon("Φεβρουάριος" std::locale::global(std::locale("en_US.utf8") try_get_mon("Febrile" }

二次

产出:

二次

Parsing the month out of '2月' in the locale ja_JP.utf8 Successfully parsed, month number is 1. The input was fully consumed Parsing the month out of 'กุมภาพันธ์' in the locale th_TH.utf8 Successfully parsed, month number is 1. The input was fully consumed Parsing the month out of 'Φεβ' in the locale el_GR.utf8 Successfully parsed, month number is 1. The input was fully consumed Parsing the month out of 'Φεβρουάριος' in the locale el_GR.utf8 Successfully parsed, month number is 1. The input was fully consumed Parsing the month out of 'Febrile' in the locale en_US.utf8 Parse failed. Unparsed string: ile

二次

另见

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[医]得到/得到[医]月名