Listing 8 The input stream operator for SPString

// Input stream operator for SPString
// allows the reading of long lines
// and lines terminated by EOF and not '\n'
istream& operator>>(istream& ifs, SPString& s)
{
char c, buf[132];
  s = ""; // initialise with an empty string
  // read a buffer from the input stream
  ifs.get(buf, sizeof buf);
  if(ifs){ // if previous operation was ok
    s += buf;   // append buffer to string
    // if its a long line continue appending to string
    while(ifs.good() && (c=ifs.get()) != '\n'){
      ifs.putback(c);
      // append to line
      if(ifs.get(buf, sizeof buf)) s += buf;
    }
  }
  return ifs;
}
// End of File