我试图将转换std::string为boost::gregorian::date这样的:
using namespace boost::gregorian;
std::string str = "1 Mar 2012";
std::stringstream ss(str);
date_input_facet *df = new date_input_facet("%e %b %Y");
ss.imbue(std::locale(ss.getloc(), df));
date d;
ss >> d; //conversion fails to not-a-date-time
std::cout << "'" << d << "'" << std::endl; //'not-a-date-time'
Run Code Online (Sandbox Code Playgroud)
但如果字符串包含"2012年3月1日",则转换成功.
如何将"2012年3月1日"等字符串转换为等效字符串boost::gregorian::date?
我有应用程序,定期(通过计时器)检查一些数据存储.
像这样:
#include <iostream>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <sys/fcntl.h>
#include <unistd.h>
// EPOLL & TIMER
#include <sys/epoll.h>
#include <sys/timerfd.h>
int main(int argc, char **argv)
{
/* epoll instance */
int efd = epoll_create1(EPOLL_CLOEXEC);
if (efd < 0)
{
std::cerr << "epoll_create error: " << strerror(errno) << std::endl;
return EXIT_FAILURE;
}
struct epoll_event ev;
struct epoll_event events[128];
/* timer instance */
int tfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
struct timespec ts;
// first expiration in 3. seconds after program start …Run Code Online (Sandbox Code Playgroud)