在 Boost 日期时间库中,是否有用于将月份短字符串(例如 Jan、Feb、Mar、Apr)转换为 boost::gregorian::greg_month 类型的实用函数?该库的文档不是很好,我在标题中看不到任何内容。
问问题
996 次
2 回答
1
一个hacky的解决方法可能是:
#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
int main(void)
{
auto ptr = boost::gregorian::greg_month::get_month_map_ptr();
if (ptr)
{
auto it = ptr->begin();
for(; it != ptr->end(); ++it)
{
std::cout << it->first << " " << it->second << '\n';
}
}
}
此映射包含所有短/长名称与创建greg_month
实例所需的短名称之间的映射。只需要在它周围创建一个小包装......
根据 Graeme 的发现,有一个方便的功能已经包装了它boost::date_time::month_str_to_ushort<>
于 2012-02-24T14:08:13.320 回答