My first question is how the data file continues. Does it continue with another three-line entry for another employee, or does it continue with further dates for the same employee (i.e. there is only one employee per file)?
Either way, you'll have to parse the string you read in. I wrote a couple of utility classes for splitting strings that you might find useful:
Splitting strings
Splitting strings again – strtok redeemed
Assuming that each file only has one empolyee, many dates, and that the format is consistent, I'd do something like this:
...
string line;
string empCode;
if (!getline(in,line))
{
return -1;
}
else
{
string_tokeniser tokeniser(line);
tokeniser.next(':');
tokeniser.next("Employee Name :");
tokeniser.get_token(empCode);
}
if (!getline(in,line))
{
return -1;
}
while (getline(in,line))
{
vector<string> lineElements;
tokenise_string(line, ' ', lineElements);
if (lineElements.size() < 6)
{
return -1;
}
out << empCode << ',' << lineElements[1] << ',' <<
lineElements[2] << ',' << lineElements[4] << endl;
}