您好我有一個非常簡單的測試用例在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
您能提供一些關於它如何失敗的更多細節,例如錯誤消息,異常,堆棧跟蹤? – 2013-03-15 19:41:03
錯誤是一個窗口彈出窗口,它表示Microsoft Visual Studio C Runtime Library在ConsoleApplication6.exe中檢測到致命錯誤。 按Break鍵調試程序或繼續終止程序。 – EddieV223 2013-03-15 19:46:35
在帖子中添加了鏈接到堆棧跟蹤。 – EddieV223 2013-03-15 19:49:38