Help with an overloading istream

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am porting some code from Solaris to Linux.  This
code is overloading the operator>> of istream. When I
compile I get the following errors:

String.C:  In function 'istream& operator>>(istream&,
String&)':
String.C:45: invalid use of undefined type 'struct
istream'
String.h:20: forward declaration of 'struct istream'

If some one could please tell me what is going on I
would appreciate it.  This does work and compile on
Solaris.  I think I am missing something put I do not
known what it is.

Here is the code for String.h

#ifndef _String_h

#ifdef _LINUX_
#include <iostream>
#endif

class istream;

class String {
    friend istream &operator>>(istream &, String &);
	
  public:
    String();
    String(const String &);
    ~String();
    const String &operator=(const String &);
    int operator!=(const char *) const;
    operator const char *() const
                  { return ptr; }
			
  protected:
  private:
    char *ptr;
};

#endif


Here is the code for String.C:

#include	<string.h>
#ifdef _LINUX_
#include	<iostream>
#else
#include	<iostream.h>
#endif

#include "String.h"

String::~String()
{
  delete [] ptr;
}

String::String(void)
    : ptr(new char[1])
{
  ptr[0] = 0;
}

int
  String::operator!=(const char *cmp) const
{
  return strcmp(ptr,cmp);
}

istream &
  operator>>(istream &in, String &s)
{
  char	buffer[256];
  buffer[0] = 0;
  in.get(buffer,256);
  delete [] s.ptr;
  s.ptr = new char [strlen(buffer) + 1];
  strcpy(s.ptr,buffer);
  return in;
}


Any help in advance is appreciated

Kevin


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you?re looking for faster
http://search.yahoo.com

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux