Question : Runtime error with decompress program.

Hey Experts.

When I try to run my program I get this error:
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file

I can't find why this is happening.
This program scans a directory for the files there and decompress all of them.
It doesn't have any file type filter because I'm just testing this directory scan code to make it part of this decompress program.

I tried to use GDB to find the answer but that didn't went well either.
Here is the last lines executed from GDB:

46          operator T& () const { return *t_; }
(gdb)
boost::iostreams::detail::read_device_impl<boost::iostreams::streambuf_tag>::read<boost::iostreams::filtering_streambuf<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char>, boost::iostreams::public_> > (t=..., s=0x806aa90 "", n=4096)
    at /usr/include/boost/iostreams/read.hpp:153
153                     0;
(gdb)
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file

Program received signal SIGABRT, Aborted.
0x0067f402 in __kernel_vsyscall ()

The code to the program is attached.
I'm trying to figure this out on my own for a while now, but I got to a point that I need to get help.
Thanks in advance.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
#include <fstream>
#include <iostream>
#include <sys/types.h>
#include <dirent.h>

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>

using namespace std;
using namespace boost::iostreams;

void decompress (string source, string filename)
{   
    ifstream file(source.c_str(), ios_base::in | ios_base::binary);
    ofstream out(filename.c_str(), ios_base::out | ios_base::binary);
    filtering_streambuf<input> in;
    in.push(zlib_decompressor());
    in.push(file);
    boost::iostreams::copy(in, out);
}

int main ()
{
    string source;
    string filename;
    char result;

    DIR* dir = opendir("/home/pablo/testee");
    struct dirent* ent = 0;

    while (dir && (ent = readdir(dir))) {
         filename = ent->d_name;
         string new_filename = filename;
         result = new_filename.find_last_of('.');

         if (std::string::npos != result)
         {
            new_filename.erase(result);
         }

         filename.append(".txt");

         decompress(ent->d_name, filename);
    }

    closedir(dir);
    
    return 0;
}

Answer : Runtime error with decompress program.

Random Solutions  
 
programming4us programming4us