Solution to exercise 4.2.1:

Only the important code pieces are presented:

#include <fstream.h>

// read original bit sequence from file bit_seq
ifstream in_file("bit_seq");

copy (istream_iterator<int, ptrdiff_t> (in_file),
      istream_iterator<int, ptrdiff_t> (), back_inserter (bit_seq) );

// store bit stuffed sequence in file bit_stff
ofstream out_file("bit_stff");

copy (bit_stuffed_seq.begin(), bit_stuffed_seq.end(),
      ostream_iterator<int> (out_file, " ") );

Back to index


Johannes Weidl (J.Weidl@infosys.tuwien.ac.at) - Apr 16, 1996