Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#1727 closed Bugs (fixed)

Sample code in documentation does not compile, has namespace errors.

Reported by: Mukkarum.Amin@… Owned by: Jonathan Turkanis
Milestone: Component: iostreams
Version: Severity: Problem
Keywords: Documentation error Cc:

Description

The example code at the very end of this http://www.boost.org/libs/iostreams/doc/classes/bzip2.html page which decompresses data from a file and writes it to standard out is erroneous and does not compile. The boost::iostream namespace is not specified. The code should be as follows, I have verified that it compiles and runs properly:

int main(int argc, char** argv)
{
  using namespace std;
  using namespace boost::iostreams;
  
  ifstream file("hello.bz2", ios_base::in | ios_base::binary);
  filtering_streambuf<input> in;
  in.push(bzip2_decompressor());
  in.push(file);
  copy(in, cout);
  return 0;
} 

Change History (4)

in reply to:  description comment:1 by Mukkarum.Amin@…, 15 years ago

Replying to Mukkarum.Amin@gmail.com:

The example code at the very end of this http://www.boost.org/libs/iostreams/doc/classes/bzip2.html page which decompresses data from a file and writes it to standard out is erroneous and does not compile. The boost::iostream namespace is not specified. The code should be as follows, I have verified that it compiles and runs properly:

int main(int argc, char** argv)
{
  using namespace std;
  using namespace boost::iostreams;
  
  ifstream file("hello.bz2", ios_base::in | ios_base::binary);
  filtering_streambuf<input> in;
  in.push(bzip2_decompressor());
  in.push(file);
  copy(in, cout);
  return 0;
} 


Forgot to add includes here is the complete code with includes:

#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>

int main(int argc, char** argv)
{
  using namespace std;
  using namespace boost::iostreams;
  
  ifstream file("hello.bz2", ios_base::in | ios_base::binary);
  filtering_streambuf<input> in;
  in.push(bzip2_decompressor());
  in.push(file);
  copy(in, cout);
  return 0;
}

comment:2 by Daniel James, 15 years ago

Component: Documentationiostreams
Owner: changed from Matias Capeletto to Jonathan Turkanis

comment:3 by Jonathan Turkanis, 14 years ago

Resolution: fixed
Status: newclosed

(In [45755]) fixed #1727

comment:4 by Jonathan Turkanis, 14 years ago

Fixed in [45755]. I left in the namespace qualification in the call to copy, because it is good practice to prevent argument-dependent lookup from find another overload of copy (e.g., std::copy from <algorithm>)

Note: See TracTickets for help on using tickets.