首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >std::put_time()的问题

std::put_time()的问题
EN

Stack Overflow用户
提问于 2013-03-16 03:33:49
回答 1查看 2.2K关注 0票数 2

您好,我这里有一个非常简单的测试用例,它在visual studio 2012下编译。但是,它会导致运行时失败。在许多与时间功能相关的示例中,复制产生此故障的代码行与在cppreference.com上完全一样。带有示例的页面,就像这样的http://en.cppreference.com/w/cpp/chrono/c/localtime

代码语言:javascript
运行
复制
#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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-16 04:02:06

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

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

不幸的是,它看起来不像是微软的一个高优先级的bug。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15440700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档