2009년 10월 5일 월요일

how to use wfstream? -- fixed setting

A typical procedure using wfstream is to use getline(fs, line) in a while loop as follows:

while(getline(fs,line)){
....
}

But, it has some problem, because this loop can be easily escaped even when fs does not reach to EOF, i.e. getline() is failed due to other errors.

To fixed this, that code needs to be changed to:

while(!getline(fs,line).eof()){
....
while(fs.fail()){
fs.clear(); //just ignore ...
}
}

This is simple ignore strategy. Maybe, a more elaborated code can be possible, by the case.

0 개의 댓글: