recently I've had to write a couple of apps that parsed text files that were a couple of gigs apiece. I wanted to output to the user that some progress is beeing made, but I don't wan't do it every line. I've come up with two solutions and was wonering which one is closer to whatever the generally acceppted best practice is.
tempc=NULL;
WR
Code:
//version 1
std::ifstream in("somefile.txt");
long buffersize=10000;//size of text buffer
char *tempc=new char[buffersize];
usigned long recordsparsed=0;
int threshold=500;//only output every threshold records
while(!in.eof())
{
cin.getline(tempc,buffersize-1);
parseline(tempc);//do stuff
recordsparsed++;
//*************************************************************
//begin relevant code
if (recordsparsed%threshold==0)
{
std::cout << recordsparsed << " records parsed" <<std::endl;
}
//end relevant code
//*************************************************************
}
delete [] tempc;
tempc=NULL;
//&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^
//version 2
std::ifstream in("somefile.txt");
long buffersize=10000;//size of text buffer
char *tempc=new char[buffersize];
usigned long recordsparsed=0;
int threshold=500;//only output every threshold records
while(!in.eof())
{
//*************************************************************
//begin relevant code
long countdown=threshold;//variable to countdown since last output
while(!in.eof()&&countdown!=0)
//end relevant code
//*************************************************************
{
cin.getline(tempc,buffersize-1);
parseline(tempc);//do stuff
recordsparsed++;
countdown--;
}
std::cout << recordsparsed << " records parsed" <<std::endl;
}
delete [] tempc;
WR