您好,我这里有一个非常简单的测试用例,它在visual studio 2012下编译。但是,它会导致运行时失败。在许多与时间功能相关的示例中,复制产生此故障的代码行与在cppreference.com上完全一样。带有示例的页面,就像这样的http://en.cppreference.com/w/cpp/chrono/c/localtime
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdio.h>
#include <chrono>
#include <string>
using namespace std;
ofstream & GetTimeStr(ofstream & ofs)
{
time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
// fails on this line, very deep inside the runtime code.
ofs << std::put_time(std::localtime(&rawTime), "%c %Z");
return ofs;
}
int main()
{
std::ofstream ofs;
ofs.open("Logger.txt");
if (ofs.good())
{
ofs << "some text " << GetTimeStr(ofs) << " more text ";
}
}
为了保持这篇文章的整洁,我将堆栈跟踪放在http://ideone.com/WaeQcf
发布于 2013-03-16 04:02:06
我猜这是VC运行时中的一个错误,它是由在strftime
(由std::put_time
调用)中使用%Z
触发的:
不幸的是,它看起来不像是微软的一个高优先级的bug。
https://stackoverflow.com/questions/15440700
复制相似问题