Re: 答复: [cpp] 请问一下 如何判断一个8位数是否是有效日期

cat street gamcat at gmail.com
Fri Sep 22 13:45:28 CST 2006


这就是boost里面相关的一个函数,不过它还弄个词法分析的说...

    //! Generic function to parse undelimited date (eg: 20020201)
    template<class date_type>
    date_type
    parse_undelimited_date(const std::string& s) {
      int offsets[] = {4,2,2};
      int pos = 0;
      typedef typename date_type::year_type year_type;
      typename date_type::ymd_type ymd((year_type::min)(),1,1);
      boost::offset_separator osf(offsets, offsets+3);
      boost::tokenizer<boost::offset_separator> tok(s, osf);
      for(boost::tokenizer<boost::offset_separator>::iterator ti=tok.begin();
ti!=tok.end();++ti) {
        unsigned short i = boost::lexical_cast<unsigned short>(*ti);
        switch(pos) {
        case 0: ymd.year = i; break;
        case 1: ymd.month = i; break;
        case 2: ymd.day = i; break;
        }
        pos++;
      }
      return date_type(ymd);
    }

在06-9-22,张沈鹏 <zsp007 at gmail.com> 写道:
>
> Boost库里有个date_time,我没有看过,不过应该可以拿来用:)
> http://www.boost.org/doc/html/date_time.html
> _______________________________________________
> Cpp mailing list
> Cpp at codingnow.com
> http://codingnow.com/mailman/listinfo/cpp
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060922/cccb235f/attachment.html


More information about the Cpp mailing list