This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Shouldn't this work?
- From: Phil Edwards <phil at jaj dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 2 May 2003 12:20:00 -0400
- Subject: Re: Shouldn't this work?
- References: <20021128204848.A25579@disaster.jaj.com> <20021203112809.52ee5318.bkoz@redhat.com>
The old thread was http://gcc.gnu.org/ml/libstdc++/2002-11/msg00335.html
and this is a missing followup.
On Tue, Dec 03, 2002 at 11:28:09AM -0600, Benjamin Kosnik wrote:
>
> Probably would be easier to figure this out if you had a full,
> self-contained test case.
Like so.
fenric 36% cat c.cc
#include <iostream>
#include <streambuf>
#include <fstream>
class comment_filter : public std::streambuf
{
public:
typedef std::streambuf base;
explicit comment_filter (base *p) : real(p) {}
virtual int_type
underflow()
{
int_type ret = real->sbumpc();
std::cerr << "have read " << (char)ret << std::endl;
if (ret == '#' || ret == ';')
{
do
{
ret = real->sbumpc();
}
while (ret != '\n' && ret != traits_type::eof());
}
std::cerr << "ret is " << (char)ret << std::endl;
return ret;
}
private:
base *real;
};
int main()
{
std::filebuf *file = new std::filebuf;
file->open("something", std::ios::in);
comment_filter *filter = new comment_filter(file);
std::istream foo (filter);
int i1 = 998, i2 = 999; // "unset" values
foo >> i1 >> i2;
std::cout << "i1 is " << i1 << " and i2 is " << i2 << std::endl;
return 0;
}
fenric 37% cat something
123456
123456
fenric 38% g++ c.cc
fenric 39% ./a.out
have read 1
ret is 1
have read 2
ret is 2
have read 3
ret is 3
have read 4
ret is 4
i1 is 2 and i2 is 999
fenric 40%
Identical results using 3.3 and trunk from this morning.