使用 sscanf 来增加日期
我正在尝试使用 sscanf 来分隔具有提升日期的字符串。这是代码:
std::sscanf(ss.c_str(),"%ls\t%lf\t%lf",&date1_,&num1_,&num2_);
我收到以下错误:
warning: format ‘%ls’ expects type ‘wchar_t*’, but argument 3 has type ‘boost::gregorian::date*’
任何人都可以建议我解决此问题。谢谢!
I am trying to use sscanf to separate a string that has a boost date. here's the code:
std::sscanf(ss.c_str(),"%ls\t%lf\t%lf",&date1_,&num1_,&num2_);
and I get the following error:
warning: format ‘%ls’ expects type ‘wchar_t*’, but argument 3 has type ‘boost::gregorian::date*’
can anyone suggest me a fix for this. thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能这样做。
sscanf
是一个 C 函数,只能读取基本类型,不能读取类类型。在 C++ 中,用于读取/写入类类型的枪是“流”,并出现在
和
标头中。如果您使用的 Boost 库的作者足够好心地重载此类的operator<<
和operator>>
,它们就会起作用。如果没有,那么最好的办法是逐一读取日期字段(作为基本类型),然后使用其构造函数创建一个
boost::gregorian::date
对象。It cannot be done this way.
sscanf
is a C function and can only read primitive types, not class types.In C++ the guns for reading/writing class types are "streams" and come in
<iostream>
and<sstream>
headers. They will work if the authors of the Boost library you're using were kind enough to overloadoperator<<
andoperator>>
for this class.If the didn't, then your best shot is to read the date fields (as basic types) one-by-one and then create a
boost::gregorian::date
object using its constructor.