![]() |
Deriving a new ifstream class
I would like to derive a new ifstream class, that would ignore comments in a file (lines that start with a '#' character). For instance:
Input file (f.txt) :
#This is a commentAn example of use :
int main(){Expected output :
ThisI know I'm suppose to derive a new streambuf and than derive the new stream using this streambuf. But I can't figure out how the new streambuf should look like (which methods should be overridden and what should they do). I think I should override the underflow method but I'm not exactly sure how. Any help would be welcome. |
Re: Deriving a new ifstream class
Why not create a separate read() function in your program that accepts the ifstream object pointer as input. The function can then read a line from the file, if it's a comment ignore it and get the next one, else return the read line.
|
| All times are GMT -5. The time now is 7:45 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC