使用sscanf作为boost日期

using sscanf for boost date

本文关键字:日期 boost 作为 sscanf 使用      更新时间:2023-10-16

我试图使用sscanf来分隔具有boost日期的字符串。下面是代码:

 std::sscanf(ss.c_str(),"%lst%lft%lf",&date1_,&num1_,&num2_);

,得到以下错误:

 warning: format ‘%ls’ expects type ‘wchar_t*’, but argument 3 has type ‘boost::gregorian::date*’

谁能建议我解决这个问题?谢谢!

不能这样做。sscanf是一个C函数,只能读取基本类型,不能读取类类型。

在c++中,读写类类型的枪是"流",来自<iostream><sstream>头。如果您正在使用的Boost库的作者足够友好地为该类重载operator<<operator>>,它们将工作。

如果没有,那么最好的方法是逐一读取日期字段(作为基本类型),然后使用其构造函数创建boost::gregorian::date对象。