由于经常会从 .csv 或 .txt 文件中读取此类字符串,因此我想知道获取%d/%m%/%y
(或任何其他类似格式)字符串并将其转换为适合QuantLib::Date
对象构造函数的字符串的最简单方法。
下面是一个示例代码:
#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#include <boost/algorithm/string.hpp>
int main() {
boost::timer timer;
std::cout << std::endl;
std::string datesString = {
",17/10/2014,21/11/2014,19/12/2014,20/03/2015,19/06/2015,18/09/2015,18/12/2015,17/06/2016,"
};
std::vector<std::string> expiryDates;
boost::split(expiryDates, datesString, boost::is_any_of(","));
for(int i = 0; i < expiryDates.size(); i++)
{
std::cout << expiryDates[i] << std::endl;
}
// 17/10/2014
// 21/11/2014
// 19/12/2014
// 20/03/2015
// 19/06/2015
// 18/09/2015
// 18/12/2015
// 17/06/2016
// QuantLib::Date myQLDate(?);
return 0;
}