Thread: Making a copy of an istream.

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    29

    Cool Making a copy of an istream.

    Hi out there!

    I have a problem with an istream object. My code is as follows:

    Code:
    //Constructor of Class scanner.
    scanner(istream &istr): is(istr) {}
    As you can see, this constructor should take an istream object as input, and copy it to a private variable called is, which also is an istream.

    This, though, does make compiling error, both with BorlandC++, and with DJGPP´s gpp.

    I have taken this from a source, which previously compiled under Unix(Solaris), with g++.

    Can anyone suggest a way to get this working(compiling)?

    Regards

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    I see nothing intrisically wrong with this, except possibly the lack of std:: qualification (you need to add std:: to every istream or using std::istream; somewhere)

    Note that having two copies of an istream object that refer to the same file can be somewhat tricky, they share a great deal of state. This, however, is not your compiler error.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    29
    Just got it working!

    I needed to write like this:
    Code:
    private:
    istream& is;
    Intead of:
    Code:
    private:
    istream is;
    Didn´t know this little detail...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  2. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  3. istream >> overloading
    By wazza13 in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2002, 10:56 PM
  4. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM
  5. copy constructor
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2001, 05:17 PM