//-------------------------------------------------------------------- // // Laboratory A, In-lab Exercise 1 strio.cpp // // String input/output operations // //-------------------------------------------------------------------- #include #include //-------------------------------------------------------------------- istream & operator >> ( istream &input, String &inputString ) // String input function. Extracts a string from istream input and // returns it in inputString. Returns the state of the input stream. { const int textBufferSize = 256; // Large (but finite) char textBuffer [textBufferSize]; // text buffer // Read a string into textBuffer, setw is used to prevent buffer // overflow. input >> setw(textBufferSize) >> textBuffer; // Apply the String(char*) constructor to convert textBuffer to // a string. Assign the resulting string to inputString using the // assignment operator. inputString = textBuffer; // Return the state of the input stream. return input; } //-------------------------------------------------------------------- ostream & operator << ( ostream &output, const String &outputString ) // String output function. Inserts outputString in ostream output. // Returns the state of the output stream. { output << outputString.buffer; return output; }