/* Exercise 4.2.1: Refine Exercise 4.1.5 by reading the original bit sequence out of a user built file bit_seq. Additionally, store the bit-stuffed bit sequence in the file bit_stff (note that the integer values in the input and output stream have to be separated by whitespaces). Hint: The output file bit_stff has to be declared as ofstream, which is defined like ifstream in fstream.h. */ #include #include #include // atoi using namespace std; void main() { list l; char ch; int input=0; list::iterator begin = l.begin(); list::iterator end = l.end(); char* ifname ="c:\\data\\stlex\\bit_seq"; // reading the original bit sequence out of a user built file bit_seq. cout<<"\nReading input file "< inv; begin = l.begin(); end = l.end(); count_1=0; while(begin!=end) { if ( count_1 < 5 ) { if ( *begin == 1 ) count_1++; inv.push_back ( *begin ); begin++; } if ( count_1 == 5 ) { count_1 =0; ; if ( *(begin++) == 1 ) // plausibility test { cerr<<"\nError, bits not stuffed correctly"; exit(0); } } } // print inverted list cout<<"\ninverted list is\n"; begin = inv.begin(); end = inv.end(); while(begin!=end) { cout<<*begin; begin++; } inv.size() == unstuffed_sz ? cout<<"\ncorrect size" : cout<<"\nincorrect size"; cin.ignore(); cout<<"\nPress any key to exit"; while(!cin.get()) ; }