Efficiency is my problem here.
I have a text file(10mb) that at (535,2) (on each line) it has a two digit code for the month. I need to make a separate file to break each month into its own file not all rows will probably be in the same file but could. Before the while loop I defined ofstream date01-date12. Exactly like this:
Code:
ofstream date01,date02,date03,date04,date05,date06,
date07,date08,date09,date10,date11,date12;
while ( getline(source2,s2Line) )
{
cout<<s2Line.substr(535,2)<<" ";
if ("01" ==s2Line.substr(535,2))
{
if (!date01)
ofstream date01("January.all");
date01<<s2Line<<endl;
g++;
}
if ("02" ==s2Line.substr(535,2))
{
if (!date02)
ofstream date02("Febuary.all");
date02<<s2Line<<endl;
g++;
}
ETC......
With this code the files are made only when the if statement is satisfied but nothing is written to them. While testing I have defined each month with its own file before the while but then I open 12 months when only three might be needed.
Any suggestion? If I was unclear let me know.