Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top