使用from_string和boost日期 [英] using from_string with boost date

查看:1012
本文介绍了使用from_string和boost日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

    #include <iostream>
#include <string>
#include <iomanip>
#include <locale>


#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/gregorian/parsers.hpp>

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>

using namespace boost::posix_time;
using namespace boost::gregorian;


int main(int argc, char *argv[])
{
 std::string ds("2011-01-02");
date dt(from_string(ds));
date_facet *f=new date_facet("%Y-%m-%d");

 std::locale loc=std::locale(std::locale::classic(),f);
std::cout.imbue(loc);


   std::cout<<dt<<std::endl;


  return 0;

}

并且当我编译它,我得到以下错误:

and when I compile it, I get the following error:

/tmp/ccBWTFcx.o: In function `unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
   b.cpp:(.text._ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs[unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x97): undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'
    collect2: ld returned 1 exit status


$ b b

这是一个库链接问题?

is this a library link issue?

推荐答案

Boost date_time不是标题,命令行,例如:

Boost date_time isn't header only, you need to link it on the command line, for example:

gcc myprogram.cpp -omyprogram -lboost_date_time

这篇关于使用from_string和boost日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆