こんにちは、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