2

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

4

1 に答える 1

4

%Zこれは、 in strftime(によって呼び出されるstd::put_time)の使用によってトリガーされるVCランタイムのバグだと思います。

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

残念ながら、Microsoftにとって優先度の高いバグではないようです。

于 2013-03-15T20:02:06.163 に答える