Making a copy of an istream.

This is a discussion on Making a copy of an istream. within the C++ Programming forums, part of the General Programming Boards category; Hi out there! I have a problem with an istream object. My code is as follows: Code: //Constructor of Class ...

  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 DJGPPs 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;
    Didnt 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-22-2005, 12:55 AM
  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, 11: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, 06:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21