// A simple, safer and efficient 8 character Buffer #ifndef BUFFER04_H #define BUFFER04_H #include #include #include #include #include using namespace std; using namespace std::rel_ops; //above defines != in terms of = for us! class Buffer { private: char buffer[8]; // unused chars set to '\0' int len;//number of characters placed in buffer void clear();//sets chars len..8 to '\0' public: Buffer():len(0){clear();}//default constructor makes an empty buffer Buffer(const char * pc);// Copy 0..8 from C text string Buffer(const Buffer & b); // copy constructor inline friend ostream& operator <<(ostream& out, const Buffer & b); //output the len characters in the buffer b inline friend istream& operator >>(istream& in, Buffer & b); //read line and store no more than the first 8 characters in b inline bool operator==(const Buffer & b)const;// test for equality virtual ~Buffer(){} //Just in Case int length()const{return len;} inline char operator[](int i) const;// safe subscript // returns '\0' when i outside 0..len }; // Buffer void Buffer::clear() { assert(0 <= len && len <=8); for(char * pc=buffer+len; pc8) len=8; for(int i=0;i=0)and(i