boost date_time库time_input_facet, %e flag有成功使用的么?

xiaocai0001 2010-09-03 07:51:32
Boost文档上写可以用, 个人尝试, 实际上只能在date_input_facet里用, time_input_facet里是不管用的, 有成功使用的么?

给个例子看看.
...全文
232 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yshuise 2010-10-15
  • 打赏
  • 举报
回复
IBM的ICU强大无比。
logiciel 2010-10-15
  • 打赏
  • 举报
回复
我曾在boost的邮件组发过2次邮件询问此问题,但不知何故没有被公布。LZ不妨去试一下。
ayw215 2010-10-15
  • 打赏
  • 举报
回复
测了下,和你的输出一样,1.4.2
ayw215 2010-10-15
  • 打赏
  • 举报
回复
囧了
你这代码我这编译都没过
xiaocai0001 2010-10-15
  • 打赏
  • 举报
回复
呃...

成死帖了...
xiaocai0001 2010-09-04
  • 打赏
  • 举报
回复
简单的测试代码如下


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

#include <iostream>
using namespace boost::posix_time;

int main()
{
std::string _format1 = "%Y-%m-%d %H:%M:%S";
std::string _format2 = "%Y-%m-%e %H:%M:%S";

std::string teststring = "2010-09-10 10:01:01";
ptime time1, time2;

time_input_facet facet1(_format1, 1);
time_input_facet facet2(_format2, 1);

std::stringstream ss1(teststring);
std::stringstream ss2(teststring);

ss1.imbue(std::locale(ss1.getloc(), &facet1));
ss1 >> time1;

ss2.imbue(std::locale(ss2.getloc(), &facet2));
ss2 >> time2;

std::cout << "Time1: " << time1 << std::endl;
std::cout << "Time2: " << time2 << std::endl;
return 0;
}


输出:

Time1: 2010-Sep-10 10:01:01
Time2: not-a-date-time

「已注销」 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xiaocai0001 的回复:]
引用 4 楼 loaden 的回复:

%d 正常?


%d OK
[/Quote]
把你代码帖出来,我帮你测试一下,我手上正好有boost 1.4.3,GCC4.4.4/VC10,不过我没用boost 1.4.4,因为最新版的boost::thread静态链接错误。
xiaocai0001 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 loaden 的回复:]

%d 正常?
[/Quote]

%d OK
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
%d 正常?
xiaocai0001 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 loaden 的回复:]

Boost版本?
建议换个boost版本试下。
[/Quote]

试过1.33.1, 1.34.1, 1.44.0, 都不管用, 抑郁了!
herman~~ 2010-09-03
  • 打赏
  • 举报
回复
我貌似都没用过过这两个,帮UP
「已注销」 2010-09-03
  • 打赏
  • 举报
回复
Boost版本?
建议换个boost版本试下。

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧