boost posix_time:stringstream输入失败

时间:2015-10-08 16:37:37

标签: c++ boost

知道为什么这会返回非日期时间,而不是时间字符串?我在Ubuntu 15.04上使用boost 1.55.0.2

#include <iostream>
#include "boost/date_time/posix_time/posix_time.hpp"

using namespace boost::posix_time;

int main(int argc, char **argv) {

    ptime t2;
    std::stringstream ss("2004-Jan-1 05:21:33.20");
    ss >> t2;

    std::cout<<t2<< std::endl;

    return 0;
}

1 个答案:

答案 0 :(得分:1)

您想要的“简单字符串”格式为YYYY-mmm-DD HH:MM:SS.fffffffff

请参阅posix time docs

这一天是两位数,所以请尝试使用std::stringstream ss("2004-Jan-01 05:21:33.20");

Live on coliru!