这是std :: get_time的一个错误? [英] is this a bug in std::get_time?
问题描述
我试图解析一个日期时间字符串,并将结果放入std :: tm结构。下面是代码,
I am trying to parse a date-time string and put the result into a std::tm structure. Below is the code,
#include <iomanip>
#include <ctime>
#include <sstream>
#include <string>
std::stringstream ss;
struct std::tm when;
ss.str("8/14/2015 3:04:23 PM");
ss >> std::get_time(&when, "%m/%d/%Y %r");
运行代码后,when.tm_hour是27.这是一个错误,错误?
After run the code, the when.tm_hour is 27. Is this a bug, or I did something wrong?
我在Windows 7上使用Visual Studio 2013.
I am using Visual Studio 2013 on windows 7.
$ b
推荐答案
您正在遇到一个错误,Microsoft的实现 std :: num_get :: do_get
函数,特别是解析AM / PM(%p
)部分的部分:
You are running into a bug in Microsoft's implementation of the std::num_get::do_get
function, specifically the section which parses the AM/PM (%p
) part of the time:
case 'p':
_Ans = _Getloctxt(_First, _Last, (size_t)0, ":AM:am:PM:pm");
if (_Ans < 0)
_State |= ios_base::failbit;
else
_Pt->tm_hour += _Ans * 12;
break;
问题是_Getloctxt在范围[0,3]中返回一个int,范围[0,1]。
The problem is that _Getloctxt returns an int in the range [0,3] and not in the expected range [0,1].
此错误已报告给Microsoft(ID: 808162 )谁声称已在Visual Studio 2015中修复它。
This bug has been reported to Microsoft (ID:808162) who claim to have fixed it in Visual Studio 2015.
这篇关于这是std :: get_time的一个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!