Cast a string to QuantLib::Day, QuantLib::Month and QuantLib::Year

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cast a string to QuantLib::Day, QuantLib::Month and QuantLib::Year

tallent_e
Hi all,

How can one cast a std::string to a QuantLib::Day, QuantLib::Month or QuantLib::Year formats?

Best,
Édouard


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Cast a string to QuantLib::Day, QuantLib::Month and QuantLib::Year

Peter Caspers-4
Hi Édouard,

to convert a string to an integer you can use

int x = boost::lexical_cast<int>("5");

QuantLib::Day and QuantLib::Year are just typedefs for int. To convert an int to QuantLib::Month you can write

QuantLib::Month m = (QuantLib::Month)x;

If x is outside 1...12 you will of course get into trouble when e.g. constructing a date.

There are also functions to parse whole dates in one sweep (dataprsers.hpp).

Kind regards
Peter


Am 03.02.2013 18:57, schrieb Edouard Tallent:
Hi all,

How can one cast a std::string to a QuantLib::Day, QuantLib::Month or QuantLib::Year formats?

Best,
Édouard



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan


_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users