[英]Problems with std::put_time()
嗨,我這里有一個非常簡單的測試用例,可以在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
我猜這是VC運行時中的一個錯誤,該錯誤是由於在strftime
使用%Z
觸發的(由std::put_time
):
不幸的是,對於Microsoft而言,它似乎並不是一個高優先級的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.