Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Some problems with Compress/Decompress program.

Avatar of PDamasceno
PDamascenoFlag for Canada asked on
Linux OS DevC++
6 Comments1 Solution1562 ViewsLast Modified:
Hey Experts.
Some days ago I posted a question here for some help with a compress/decompress program.
Got the help I needed and wrote the code below to test with boost iostreams a little bit and finally get to where I want to.

(I'm new to C++ development so it is possible to have syntax erros in the code, point them out for me if you see any please!)

#include <iostream>
#include <sstream>

#include </usr/include/boost/assign/list_of.hpp>
#include </usr/include/boost/iostreams/copy.hpp>
#include </usr/include/boost/iostreams/device/back_inserter.hpp>
#include </usr/include/boost/iostreams/filter/zlib.hpp>
#include </usr/include/boost/iostreams/filtering_stream.hpp>

//-----------------------------------------------------------------------------
void
    compress
    (
        const std::string& data,
        std::string&       buffer
    )
{
    buffer.clear();
    boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
    out.push(boost::iostreams::zlib_compressor());
    out.push(boost::iostreams::back_inserter(buffer));
    boost::iostreams::copy(boost::make_iterator_range(data), out);
}

//----------------------------------------------------------------------------
void
    decompress
    (
        const std::string& buffer,
        std::string&       data
    )
{
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    in.push(boost::make_iterator_range(buffer));
    data.clear();
    boost::iostreams::copy(in, boost::iostreams::back_inserter(data));
}

//----------------------------------------------------------------------------
int main()
{
    const std::string send_data = "Test, test, test, test!!!!!";
    std::string received_data;
    std::string buffer;

    compress(send_data, buffer);
    decompress(buffer, received_data);
   
    if(send_data == received_data)
       std::cout << send_data << " equals " << received_data << std::endl;
    else
       std::cout << "Erro: " << send_data << " differs from " << received_data << std::endl;

    return 0;
}

But I keep getting this freaking error while trying to compile it:

testedc.cpp: In function ‘int main()’:
testedc.cpp:45: error: invalid conversion from ‘int’ to ‘const char*’
testedc.cpp:45: error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’

I can't find that invalid conversion it is telling me.
Can you guys help me with this?
Also, I would like you guys to take a look in my code up there and see if everything is fine with it.

A couple more questions:
* How can I make the file go to a specific directory after it is compressed?
* If the file to decompress is not in a buffer but in a directory, how can I tell the function decompress() to work?
* If the path to the file needed be decompressed is stored in other variable, how can I tell the function decompress() to work?
* How can I handle possible exception errors from compress() and decompress()?
* Any thoughts on how to make this program the most efficient possible, in terms of speed of the compress and decompress functions?
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers