L E D A  goes Compression
Example 1: Coders and Decoders


Example 1:
Writing to and reading from a compressed file.

#include <LEDA/string.h>
#include <LEDA/compression.h> // contains all compression classes

using namespace LEDA;

typedef HuffmanCoder Coder;

int main()
{
        string str = "Hello World";

        encoding_ofstream<Coder> out("foo");
        out << str << "\n";
        out.close();
        if (out.fail()) std::cout << "error writing foo" << "\n";

        decoding_ifstream<Coder> in("foo");
        in >> str;
        in.close();
        if (in.fail()) std::cout << "error reading foo" << "\n";

        std::cout << "decoded string: " << str << "\n";

        return 0;
}


We want to emphasize that the classes encoding_ofstream and decoding_ofstream can not only be used together with L E D A datatypes, all operations and operators (« and ») defined for C++ streams can be applied to them as well.

Copyright © 1998-2007 Algorithmic Solutions Software GmbH. All rights reserved.