help debug overloading <<

This is a discussion on help debug overloading << within the C++ Programming forums, part of the General Programming Boards category; This is the first error of several. If you could explain to me what I am doing wrong here I ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    help debug overloading <<

    This is the first error of several. If you could explain to me what I am doing wrong here I can continue to debug the rest on my own
    Here is the main code.
    Code:
    using namespace std;
    #include "complexh.hpp"
    
    
    int main()
    {
        Complex a(3.0,4.0);  // instantiate a 
        Complex c;
        cout << "Enter a complex number (q to quit):\n";
        while (cin>>c) //                                                    error here
    
        { 
            cout << "c is " << c << endl;
            cout << "complex conjugate is " << ~c << '\n';
            cout << "a+c is "<< a+c << endl;
            cout << "a-c is "<< a-c << endl;
            cout << "a*c is "<< a*c << endl;
            cout << "2*c is "<< 2*c << endl;
            cout << "Enter a complex number (q to quit):\n"
        }
                
      cout << "Done!\n";
      system("PAUSE");	
      return 0;
    }
    Here is the prototype and function definiton
    Code:
    friend ostream & operator>>(ostream & os,const Complex & n);
    
    ostream & operator>>(ostream & os,const Complex & n);
    {
        cout << "real:";
        os >> n.rel;
        cout << endl;
        cout << "imaginary:";
        os >> n.imaginary;
        cout << endl;
        return os;
    }

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    doh istream not ostream

    Here is an example where the book doesn't tell you everything.

    I replaced the ostream object with istream and walla it works

    By paying close attention to the compiler errors I figured it out.

    Now I have one more problem given the imaginary number (3,4i)
    subtracting (10,12 i) the output should be (-7,-8i) right?

    The books output says (13,16i) who is correct me or the book?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overloading <<
    By msshapira in forum C++ Programming
    Replies: 2
    Last Post: 05-06-2009, 02:11 PM
  2. Overloading fstream's << and >> operators
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 03:17 AM
  3. Overloading the << operator.
    By antex in forum C++ Programming
    Replies: 5
    Last Post: 05-31-2005, 01:37 AM
  4. need help with overloading << , please
    By hkl in forum C++ Programming
    Replies: 4
    Last Post: 02-16-2005, 01:30 PM
  5. Simple Overloading of Operator '<<'
    By tegwin in forum C++ Programming
    Replies: 12
    Last Post: 11-03-2002, 09:31 AM

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