2

嗨,我在这里有一个非常简单的测试用例,可以在 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

4

1 回答 1

4

我猜这是 VC 运行时中的一个错误,它是由使用%Zin触发的strftime(由 调用std::put_time):

http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code

不幸的是,它看起来不像是微软的高优先级错误。

于 2013-03-15T20:02:06.163 回答