2013-03-15 81 views
2

您好我有一个非常简单的测试用例在visual studio 2012下编译。但它会产生运行时失败。产生这种故障的线路被完全复制,就像在时间功能相关的示例中的cppreference.com上一样。 页用例子就这样http://en.cppreference.com/w/cpp/chrono/c/localtime问题与std :: put_time()

#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

+0

您能提供一些关于它如何失败的更多细节,例如错误消息,异常,堆栈跟踪? – 2013-03-15 19:41:03

+0

错误是一个窗口弹出窗口,它表示Microsoft Visual Studio C Runtime Library在ConsoleApplication6.exe中检测到致命错误。 按Break键调试程序或继续终止程序。 – EddieV223 2013-03-15 19:46:35

+0

在帖子中添加了链接到堆栈跟踪。 – EddieV223 2013-03-15 19:49:38

回答