I.
I have a csv file that looks like this:
XXXX,20140101
XXXX,20140102
XXXX,20140103
XXXX,20140108
XXXX,20140212
and so on, it's much larger than just that.
II.
The following method call will start the process I want to design:
Calendar XXXXCal = FromFile("h:\\temp\\XXXXdata.csv","XXXX");
III.
Using C++ I would like to read take those input parameters, which consists of a file and a specific value. The following code illustrates to some degree what I'm trying to do, first, take a look at it, and below I'll further clarify my intent.
BespokeCalendar Calendar::XXXXCal(string input_file_name, string input_market)
{
/* Declare the variables to be used */
BespokeCalendar result;
string filename = input_file_name;
string marekt = input_market;
string csvLine
string csvMarket;
string csvDate;
ifstream csvFile ( filename ); // declare file stream
if( csvFile.good()) )
{
while (getline (csvFile,csvLine)
{
var containerArray = line.Split(",");
var csvDate = containerArray[1];
var csvMarket = containerArray[0];
if (csvMarket == marekt)
{
result.addHoliday( csvDate );
}
}
}
else
{
cout << "Unable to open file";
}
result.addWeekend();
return result;
}
So as you can see I want to read from the csv file, line by line, something which the above code certainly does not accomplish. I've read that the ifstream handles iteration over the file, and that the getline will get me to the next line, is it so? How does that work?
I'm also doubtful that the split method exists like that, do I have to construct it out of "find_first_of" and "substr"?
How can I write a reasonable test script for this?
I'm modifying the calendar class of QuantLib.