![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2005
Location: In the minds of all true communists.
Posts: 16
Rep Power: 0
![]() |
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 comment This is not An example of use int main(){
string a;
commentStream cs("f.txt");
if(!cs) exit(1);
else{
while(cs){
cs >> a;
cout << a << endl;
}
}
return (0);
}Expected output This is not I 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.
__________________
Science progresses one death at a time - Niels Bohr |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| template class | brad sue | C++ | 1 | Mar 25th, 2007 6:46 PM |
| URL class | Eric the Red | Java | 5 | Jun 24th, 2006 10:01 PM |
| Problem with class constructor | paeck | C++ | 8 | Feb 7th, 2006 1:53 PM |
| using classes in another class | ling_wong | C++ | 6 | Jan 23rd, 2006 10:55 PM |
| MFC/OpenGL: problem with 'Document' class | brenda | C++ | 11 | May 23rd, 2005 9:10 PM |