开发者

using sscanf for boost date

I am trying to use sscanf to separ开发者_开发问答ate 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!


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 overload operator<< and operator>> 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜