Download the cpp file.

#include <stdlib.h>
#include "fileio.h"


FileReader::FileReader()
{
  buffer = NULL;
  cursor = NULL;
  end    = NULL;
  size   = 0;
  eof    = false;
}

//_______________________________________________

FileReader::FileReader(long sz)
{
  if (sz)
    buffer = new char [sz];
  else
    buffer = NULL;

  cursor = buffer;
  end    = buffer;
  size   = sz;
  eof    = false;
}

//_______________________________________________

FileReader::~FileReader()
{
  delete [] buffer;
}

//_______________________________________________

void FileReader::SetSize(long sz)
{
  delete [] buffer;
  if (sz)
    buffer = new char [sz];
  else
    buffer = NULL;

  cursor = buffer;
  end    = buffer;
  size   = sz;
  eof    = false;
}

//_______________________________________________

bool FileReader::Open(const Str &name)
{
  file.open(name.String());
  line = 0;
  return file;
}

//_______________________________________________

bool FileReader::Open(const char *name)
{
  file.open(name);
  line = 0;
  return file;
}

//_______________________________________________

void FileReader::Read()
{
  if (!buffer)
    throw Str("file read buffer not initialized.");

  file.read(buffer, size);
  long len = file.gcount();
  eof      = len < size;
  cursor   = buffer;
  end      = buffer + len;
}

//_______________________________________________
// Skip over white-space characters.

bool FileReader::SkipSpaces()
{
  Loop:
  while (isspace(*cursor) && cursor < end)
  {
    if (*cursor == '\n')
      line++;

    cursor++;
  }

  if (end <= cursor)
  {
    if (eof)
      return false;

    file.read(buffer, size);          // Read a new block.
    long len = file.gcount();
    eof      = len < size;
    cursor   = buffer;
    end      = buffer + len;
    goto Loop;
  }

  return true;
}

//_______________________________________________
// Get the first nonwhite-space character.

bool FileReader::GetCharacter(char &ch)
{
  Loop:
  while (isspace(*cursor) && cursor < end)
  {
    if (*cursor == '\n')
      line++;

    cursor++;
  }

  if (end <= cursor)
  {
    if (eof)
      return false;

    file.read(buffer, size);          // Read a new block.
    long len = file.gcount();
    eof      = len < size;
    cursor   = buffer;
    end      = buffer + len;
    goto Loop;
  }

  ch = *cursor;
  cursor++;
  return true;
}

//_______________________________________________
// Parse a token delimited by white-space characters.

bool FileReader::GetToken(Str &token)
{
  char *start;
  long  len1, len2;

  token.length  = 0;
  *token.string = '\0';

  Loop1:
  while (isspace(*cursor) && cursor < end)
  {
    if (*cursor == '\n')
      line++;

    cursor++;
  }

  if (end <= cursor)
  {
    if (eof)
      return false;

    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    end    = buffer + len1;
    goto Loop1;
  }

  Loop2:
  start = cursor;
  while (!isspace(*cursor) && cursor < end)
    cursor++;

  len1 = cursor - start;
  len2 = token.length + len1;
  if (token.size <= len2)
  {
    token.size = len2 << 1;
    char *str = new char [token.size];
    if (!str)
      token.AlError();

    strcpy(str, token.string);
    delete [] token.string;
    token.string = str;
  }

  strncpy(token.string + token.length, start, len1);
  token.string[len2] = '\0';
  token.length = len2;

  if (end <= cursor && !eof)
  {
    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    start  = buffer;
    end    = buffer + len1;
    goto Loop2;
  }

  return true;
}

//_______________________________________________
// Skip over tokens delimited by white-space characters.

bool FileReader::SkipToken(int n)
{
  long len;

  for ( ; n; n--)
  {
    Loop1:
    while (isspace(*cursor) && cursor < end)
    {
      if (*cursor == '\n')
        line++;

      cursor++;
    }

    if (end <= cursor)
    {
      if (eof)
        return false;

      file.read(buffer, size);          // Read a new block.
      len    = file.gcount();
      eof    = len < size;
      cursor = buffer;
      end    = buffer + len;
      goto Loop1;
    }

    Loop2:
    while (!isspace(*cursor) && cursor < end)
      cursor++;

    if (end <= cursor)
    {
      if (eof)
        return false;

      file.read(buffer, size);          // Read a new block.
      len    = file.gcount();
      eof    = len < size;
      cursor = buffer;
      end    = buffer + len;
      goto Loop2;
    }
  }

  return true;
}

//_______________________________________________
// Parse a token delimited by a given delimiter.

bool FileReader::GetToken(Str &token, char delimiter)
{
  token.length  = 0;
  *token.string = '\0';

  if (end <= cursor && eof)
    return false;

  char *start;
  long len1, len2;

  Loop:
  start = cursor;
  while (*cursor != delimiter && cursor < end)
  {
    if (*cursor == '\n')
      line++;

    cursor++;
  }

  len1 = cursor - start;
  len2 = token.length + len1;
  if (token.size <= len2)
  {
    token.size = len2 << 1;
    char *str = new char [token.size];
    if (!str)
      token.AlError();

    strcpy(str, token.string);
    delete [] token.string;
    token.string = str;
  }

  strncpy(token.string + token.length, start, len1);
  token.string[len2] = '\0';
  token.length = len2;

  if (end <= cursor)
  {
    if (eof)
      return true;

    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    end    = buffer + len1;
    goto Loop;
  }

  cursor++;
  return true;
}

//_______________________________________________

bool FileReader::SkipToken(char delimiter, int n)
{
  for ( ; n; n--)
  {
    Loop:
    while (*cursor != delimiter && cursor < end)
    {
      if (*cursor == '\n')
        line++;

      cursor++;
    }

    if (end <= cursor)
    {
      if (eof)
        return false;

      file.read(buffer, size);          // Read a new block.
      long len = file.gcount();
      eof    = len < size;
      cursor = buffer;
      end    = buffer + len;
      goto Loop;
    }

    cursor++;
  }

  return true;
}

//_______________________________________________
// Get a line.

bool FileReader::GetLine(Str &token)
{
  token.length  = 0;
  *token.string = '\0';

  if (end <= cursor && eof)
    return false;

  char *start;
  long len1, len2;

  Loop:
  start = cursor;
  while (*cursor != '\n' && cursor < end)
    cursor++;

  len1 = cursor - start;
  len2 = token.length + len1;
  if (token.size <= len2)
  {
    token.size = len2 << 1;
    char *str = new char [token.size];
    if (!str)
      token.AlError();

    strcpy(str, token.string);
    delete [] token.string;
    token.string = str;
  }

  strncpy(token.string + token.length, start, len1);
  token.string[len2] = '\0';
  token.length = len2;

  if (end <= cursor)
  {
    if (eof)
      return true;

    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    end    = buffer + len1;
    goto Loop;
  }

  cursor++;
  line++;

  return true;
}

//_______________________________________________
// Get the first non-blank line.

bool FileReader::GetTextLine(Str &token)
{
  char *start;
  long len1, len2;

  Loop1:
  token.length  = 0;
  *token.string = '\0';

  Loop2:
  if (end <= cursor && eof)
    return false;

  start = cursor;
  while (*cursor != '\n' && cursor < end)
    cursor++;

  len1 = cursor - start;
  len2 = token.length + len1;
  if (token.size <= len2)
  {
    token.size = len2 << 1;
    char *str = new char [token.size];
    if (!str)
      token.AlError();

    strcpy(str, token.string);
    delete [] token.string;
    token.string = str;
  }

  strncpy(token.string + token.length, start, len1);
  token.string[len2] = '\0';
  token.length = len2;

  if (end <= cursor && !eof)
  {
    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    end    = buffer + len1;
    goto Loop2;
  }

  cursor++;
  line++;

  for (len1 = 0; len1 < len2; len1++)
  {
    if (!isspace(token.string[len1]))
      return true;
  }

  goto Loop1;
}

//_______________________________________________
// Get a line.

FileReader &FileReader::operator>>(Str &token)
{
  token.length  = 0;
  *token.string = '\0';

  if (end <= cursor && eof)
    return *this;

  char *start;
  long len1, len2;

  Loop:
  start = cursor;
  while (*cursor != '\n' && cursor < end)
    cursor++;

  len1 = cursor - start;
  len2 = token.length + len1;
  if (token.size <= len2)
  {
    token.size = len2 << 1;
    char *str = new char [token.size];
    if (!str)
      token.AlError();

    strcpy(str, token.string);
    delete [] token.string;
    token.string = str;
  }

  strncpy(token.string + token.length, start, len1);
  token.string[len2] = '\0';
  token.length = len2;

  if (end <= cursor)
  {
    if (eof)
      return *this;

    file.read(buffer, size);          // Read a new block.
    len1   = file.gcount();
    eof    = len1 < size;
    cursor = buffer;
    end    = buffer + len1;
    goto Loop;
  }

  cursor++;
  line++;

  return *this;
}

//_______________________________________________

bool FileReader::SkipLine(int n)
{
  for ( ; n; n--)
  {
    Loop:
    while (*cursor != '\n' && cursor < end)
      cursor++;

    if (end <= cursor)
    {
      if (eof)
        return false;

      file.read(buffer, size);          // Read a new block.
      long len = file.gcount();
      eof      = len < size;
      cursor   = buffer;
      end      = buffer + len;
      goto Loop;
    }

    cursor++;
    line++;
  }

  return true;
}

//___________________________________________________________________________
//___________________________________________________________________________


FileWriter::FileWriter()
{
  buffer = NULL;
  cursor = NULL;
  end    = NULL;
  size   = 0;
}

//_______________________________________________

FileWriter::FileWriter(long sz)
{
  if (sz)
    buffer = new char [sz];
  else
    buffer = NULL;

  cursor = buffer;
  end    = buffer + sz;
  size   = sz;
}

//_______________________________________________

FileWriter::~FileWriter()
{
  delete [] buffer;
}

//_______________________________________________

void FileWriter::SetSize(long sz)
{
  delete [] buffer;
  if (sz)
    buffer = new char [sz];
  else
    buffer = NULL;

  cursor = buffer;
  end    = buffer + sz;
  size   = sz;
}

//_______________________________________________

bool FileWriter::Open(const Str &name)
{
  cursor = buffer;
  file.open(name.String());
  return file;
}

//_______________________________________________

bool FileWriter::Open(const char *name)
{
  cursor = buffer;
  file.open(name);
  return file;
}

//_______________________________________________

void FileWriter::Write()
{
  long length = cursor - buffer;
  if (length)
  {
    file.write(buffer, length);
    cursor = buffer;
  }
}

//_______________________________________________

void FileWriter::Append(const Str &src)
{
  char *ptr = cursor + src.length;
  if (ptr < end)
  {
    memcpy(cursor, src.string, src.length);
    cursor = ptr;
  }

  else
  {
    long len1 = end - cursor;
    memcpy(cursor, src.string, len1);
    file.write(buffer, size);

    long len2 = src.length - len1;
    memcpy(buffer, src.string + len1, len2);
    cursor = buffer + len2;
  }
}

//_______________________________________________

void FileWriter::Append(const char *src)
{
  long lenS = strlen(src);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, src, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, src, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, src + len, lenS);
    cursor = buffer + lenS;
  }
}

//_______________________________________________

void FileWriter::Append(char src)
{
  *cursor = src;
  cursor++;
  if (cursor == end)
  {
    file.write(buffer, size);
    cursor = buffer;
  }
}

//_______________________________________________

void FileWriter::Append(long number)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
  }

  delete numStr;
}

//_______________________________________________

void FileWriter::Append(double number)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
  }

  delete numStr;
}

//_______________________________________________

FileWriter &FileWriter::operator<<(const Str &src)
{
  char *ptr = cursor + src.length;
  if (ptr < end)
  {
    memcpy(cursor, src.string, src.length);
    cursor = ptr;
  }

  else
  {
    long len1 = end - cursor;
    memcpy(cursor, src.string, len1);
    file.write(buffer, size);

    long len2 = src.length - len1;
    memcpy(buffer, src.string + len1, len2);
    cursor = buffer + len2;
  }

  return *this;
}

//_______________________________________________

FileWriter &FileWriter::operator<<(const char *src)
{
  long lenS = strlen(src);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, src, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, src, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, src + len, lenS);
    cursor = buffer + lenS;
  }

  return *this;
}

//_______________________________________________

FileWriter &FileWriter::operator<<(char src)
{
  *cursor = src;
  cursor++;
  if (cursor == end)
  {
    file.write(buffer, size);
    cursor = buffer;
  }

  return *this;
}

//_______________________________________________

FileWriter &FileWriter::operator<<(long number)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
  }

  delete numStr;
  return *this;
}

//_______________________________________________

FileWriter &FileWriter::operator<<(double number)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    cursor = ptr;
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
  }

  delete numStr;
  return *this;
}

//_______________________________________________

void FileWriter::Append(const Str &src, char delimiter)
{
  char *ptr = cursor + src.length;
  if (ptr < end)
  {
    memcpy(cursor, src.string, src.length);
    *ptr = delimiter;
    cursor = ptr + 1;

    if (cursor == end)
    {
      file.write(buffer, size);
      cursor = buffer;
    }
  }

  else
  {
    long len1 = end - cursor;
    memcpy(cursor, src.string, len1);
    file.write(buffer, size);

    long len2 = src.length - len1;
    memcpy(buffer, src.string + len1, len2);
    cursor = buffer + len2;
    *cursor = delimiter;
    cursor++;
  }
}

//_______________________________________________

void FileWriter::Append(const char *src, char delimiter)
{
  long lenS = strlen(src);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, src, lenS);
    *ptr = delimiter;
    cursor = ptr + 1;

    if (cursor == end)
    {
      file.write(buffer, size);
      cursor = buffer;
    }
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, src, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, src + len, lenS);
    cursor = buffer + lenS;
    *cursor = delimiter;
    cursor++;
  }
}

//_______________________________________________

void FileWriter::Append(char src, char delimiter)
{
  *cursor = src;
  cursor++;
  if (cursor == end)
  {
    file.write(buffer, size);
    cursor = buffer;
  }

  *cursor = delimiter;
  cursor++;
  if (cursor == end)
  {
    file.write(buffer, size);
    cursor = buffer;
  }
}

//_______________________________________________

void FileWriter::Append(long number, char delimiter)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    *ptr = delimiter;
    cursor = ptr + 1;

    if (cursor == end)
    {
      file.write(buffer, size);
      cursor = buffer;
    }
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
    *cursor = delimiter;
    cursor++;
  }

  delete numStr;
}

//_______________________________________________

void FileWriter::Append(double number, char delimiter)
{
  ostrstream ostr;
  ostr << number << ends;
  char *numStr = ostr.str();
  long lenS = strlen(numStr);
  char *ptr = cursor + lenS;
  if (ptr < end)
  {
    memcpy(cursor, numStr, lenS);
    *ptr = delimiter;
    cursor = ptr + 1;

    if (cursor == end)
    {
      file.write(buffer, size);
      cursor = buffer;
    }
  }

  else
  {
    long len = end - cursor;
    memcpy(cursor, numStr, len);
    file.write(buffer, size);

    lenS -= len;
    memcpy(buffer, numStr + len, lenS);
    cursor = buffer + lenS;
    *cursor = delimiter;
    cursor++;
  }

  delete numStr;
}

//_______________________________________________

void FileWriter::Append(const Str &src, long len, bool justify)
{
  char *ptr, *ptr1, *ptr2;
  long lenB;

  if (len < src.length)
    len = src.length;

  lenB = len - src.length;
  ptr = cursor + len;
  if (ptr < end)
  {
    ptr1 = cursor;
    ptr2 = cursor;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += src.length;

    memcpy(ptr1, src.string, src.length);
    memset(ptr2, ' ', lenB);
    cursor = ptr;
  }

  else
  {
    ptr  = new char [len];
    ptr1 = ptr;
    ptr2 = ptr;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += src.length;

    memcpy(ptr1, src.string, src.length);
    memset(ptr2, ' ', lenB);

    lenB = end - cursor;
    memcpy(cursor, ptr, lenB);
    file.write(buffer, size);

    len -= lenB;
    memcpy(buffer, ptr + lenB, len);
    cursor = buffer + len;
    delete [] ptr;
  }
}

//_______________________________________________

void FileWriter::Append(const char *src, long len, bool justify)
{
  char *ptr, *ptr1, *ptr2;
  long lenS, lenB;

  lenS = strlen(src);
  if (len < lenS)
    len = lenS;

  lenB = len - lenS;
  ptr = cursor + len;
  if (ptr < end)
  {
    ptr1 = cursor;
    ptr2 = cursor;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, src, lenS);
    memset(ptr2, ' ', lenB);
    cursor = ptr;
  }

  else
  {
    ptr  = new char [len];
    ptr1 = ptr;
    ptr2 = ptr;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, src, lenS);
    memset(ptr2, ' ', lenB);

    lenB = end - cursor;
    memcpy(cursor, ptr, lenB);
    file.write(buffer, size);

    len -= lenB;
    memcpy(buffer, ptr + lenB, len);
    cursor = buffer + len;
    delete [] ptr;
  }
}

//_______________________________________________

void FileWriter::Append(char src, long len, bool justify)
{
  char *ptr;

  if (len < 1)
    len = 1;

  ptr = cursor + len;
  if (ptr < end)
  {
    memset(cursor, ' ', len);
    if (justify)
      cursor[len - 1] = src;

    else
      *cursor = src;

    cursor = ptr;
  }

  else
  {
    long lenB;

    ptr  = new char [len];
    memset(ptr, ' ', len);

    if (justify)
      ptr[len - 1] = src;

    else
      *ptr = src;

    lenB = end - cursor;
    memcpy(cursor, ptr, lenB);
    file.write(buffer, size);

    len -= lenB;
    memcpy(buffer, ptr + lenB, len);
    cursor = buffer + len;
    delete [] ptr;
  }
}

//_______________________________________________

void FileWriter::Append(long number, long len, bool justify)
{
  ostrstream ostr;
  char *numStr, *ptr, *ptr1, *ptr2;
  long lenS, lenB;

  ostr << number << ends;
  numStr = ostr.str();
  lenS = strlen(numStr);
  if (len < lenS)
    len = lenS;

  lenB = len - lenS;
  ptr = cursor + len;
  if (ptr < end)
  {
    ptr1 = cursor;
    ptr2 = cursor;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, numStr, lenS);
    memset(ptr2, ' ', lenB);
    cursor = ptr;
  }

  else
  {
    ptr  = new char [len];
    ptr1 = ptr;
    ptr2 = ptr;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, numStr, lenS);
    memset(ptr2, ' ', lenB);

    lenB = end - cursor;
    memcpy(cursor, ptr, lenB);
    file.write(buffer, size);

    len -= lenB;
    memcpy(buffer, ptr + lenB, len);
    cursor = buffer + len;
    delete [] ptr;
  }

  delete numStr;
}

//_______________________________________________

void FileWriter::Append(double number, long len, bool justify)
{
  ostrstream ostr;
  char *numStr, *ptr, *ptr1, *ptr2;
  long lenS, lenB;

  ostr << number << ends;
  numStr = ostr.str();
  lenS = strlen(numStr);
  if (len < lenS)
    len = lenS;

  lenB = len - lenS;
  ptr = cursor + len;
  if (ptr < end)
  {
    ptr1 = cursor;
    ptr2 = cursor;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, numStr, lenS);
    memset(ptr2, ' ', lenB);
    cursor = ptr;
  }

  else
  {
    ptr  = new char [len];
    ptr1 = ptr;
    ptr2 = ptr;
    if (justify)
      ptr1 += lenB;

    else
      ptr2 += lenS;

    memcpy(ptr1, numStr, lenS);
    memset(ptr2, ' ', lenB);

    lenB = end - cursor;
    memcpy(cursor, ptr, lenB);
    file.write(buffer, size);

    len -= lenB;
    memcpy(buffer, ptr + lenB, len);
    cursor = buffer + len;
    delete [] ptr;
  }

  delete numStr;
}

//_______________________________________________

void FileWriter::RemoveEndBlankLines()
{
  if (cursor > buffer)
  {
    for (cursor--; cursor > buffer; cursor--)
    {
      if (!isspace(*cursor))
        break;
    }

    for (cursor++; cursor < end; cursor++)
    {
      if (*cursor == '\n')
      {
        cursor++;
        break;
      }
    }
  }
}

//___________________________________________________________________________
//___________________________________________________________________________

void CoutWriter::Append(const Str &src, long len, bool justify)
{
  len -= src.Length();
  if (len < 0)
    len = 0;

  Str blanks(' ', len);
  if (justify)
    cout << blanks << src;

  else
    cout << src << blanks;
}

//_______________________________________________

void CoutWriter::Append(const char *src, long len, bool justify)
{
  len -= strlen(src);
  if (len < 0)
    len = 0;

  Str blanks(' ', len);
  if (justify)
    cout << blanks << src;

  else
    cout << src << blanks;
}

//_______________________________________________

void CoutWriter::Append(char src, long len, bool justify)
{
  len--;
  if (len < 0)
    len = 0;

  Str blanks(' ', len);
  if (justify)
    cout << blanks << src;

  else
    cout << src << blanks;
}

//_______________________________________________

void CoutWriter::Append(long number, long len, bool justify)
{
  ostrstream ostr;

  ostr << number << ends;
  char *numStr = ostr.str();
  len -= strlen(numStr);
  if (len < 0)
    len = 0;

  Str blanks(' ', len);
  if (justify)
    cout << blanks << numStr;

  else
    cout << numStr << blanks;

  delete numStr;
}

//_______________________________________________

void CoutWriter::Append(double number, long len, bool justify)
{
  ostrstream ostr;

  ostr << number << ends;
  char *numStr = ostr.str();
  len -= strlen(numStr);
  if (len < 0)
    len = 0;

  Str blanks(' ', len);
  if (justify)
    cout << blanks << numStr;

  else
    cout << numStr << blanks;

  delete numStr;
}

//_______________________________________________

FileWriter &CoutWriter::operator<<(const Str &s)
{
  cout << s;
  return *this;
}

//_______________________________________________

FileWriter &CoutWriter::operator<<(const char *s)
{
  cout << s;
  return *this;
}

//_______________________________________________

FileWriter &CoutWriter::operator<<(char s)
{
  cout << s;
  return *this;
}

//_______________________________________________

FileWriter &CoutWriter::operator<<(long n)
{
  cout << n;
  return *this;
}

//_______________________________________________

FileWriter &CoutWriter::operator<<(double n)
{
  cout << n;
  return *this;
}