|
Boost Users : |
From: Jonathan Turkanis (turkanis_at_[hidden])
Date: 2008-02-13 17:02:02
ope wrote:
> Hi,
>
> I've the following code:
>
> namespace io = boost::iostreams;
>
> bool foo::open( const std::string& file )
> {
> io::filtering_istream is;
>
> is.push( my_line_filter() );
> is.push( io::file_source( file ) );
>
> // ??? how to check success
>
> do {
> std::string line;
> std::getline(is, line);
> std::cout << line << std::endl;
> } while (!is.eof());
>
> return true;
> }
>
> Well, how can I check that the file is opened correct/the stream is
> valid? is_open() and good() seems not supported? Or I'm wrong? Giving a
> wrong name does nothings.
Use file_source::is_open() (http://tinyurl.com/29o2wm). You can call it
before adding the filter to the chain:
file_source src(file);
if (!is_open(src)) { ... }
...
is.push(src);
or after adding it (http://tinyurl.com/2cmlke):
is.push(my_line_filter());
is.push(file_source(file));
if (!is.component<file_source>(1).is_open())
....
Here 1 is the offset of the file_source in the filter chain.
> Thanks,
> Olaf
-- Jonathan Turkanis CodeRage http://www.coderage.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net