我试图以这种方式将 std::string 转换为 boost::gregorian::date :
#include <iostream>
#include "boost/date_time/gregorian/gregorian.hpp"
int main(int argc, char *argv[])
{
std::string s_date = "1922-02-29";
std::stringstream ss(s_date);
boost::gregorian::date_input_facet *df = new boost::gregorian::date_input_facet("%Y-%m-%d");
ss.imbue(std::locale(ss.getloc(), df));
date d;
ss>>d;
std::cout<<d<<std::endl;
}
但不幸的是,我只收到了“not-a-date-time”。我做错了什么?有没有更简单的方法可以将如此流行的字符串转换为 boost::gregorian:date?