#1727 closed Bugs (fixed)
Sample code in documentation does not compile, has namespace errors.
| Reported by: | 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)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
| Component: | Documentation → iostreams |
|---|---|
| Owner: | changed from to |
comment:4 by , 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.

Replying to Mukkarum.Amin@gmail.com:
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; }