overloaded >> operator issue...

This is a discussion on overloaded >> operator issue... within the C++ Programming forums, part of the General Programming Boards category; Hey i am using an overloaded operator '>>' in one of my cpp files (see code below). I want to ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    5

    overloaded >> operator issue...

    Hey

    i am using an overloaded operator '>>' in one of my cpp files (see code below).

    I want to still be able to use "cout" to do screen output, but when i use it, i get the following error:

    Code:
    no match for `std::ostream& >> const char[43]' operator
    i understand that this error is because of the overloaded operator, but how can i get my program to use the standard '>>' so i can use cout? ...

    i also tried using cout.operator(" ... "); but that resulted in the error:

    Code:
    no matching function for call to `std::basic_ostream<char,   std::char_traits<char> >::<invalid operator>(const char[43])'
    Any help would be appreciated.

    cheers
    SR.

    the call to the overloaded operator:

    Code:
    void Asteroid::mass_loss( int hours )
    {
       // need to add 4 and 12 hour code here... 
    
       if(hours == 4)
       {
    
    
       }else if(hours == 12)
       {
           
    
       }else
       {
          cout.operator("incorrect hours entered. Please try again.");
       }
    }
    and the overloaded operator:

    Code:
    ostream& operator << ( ostream& os, const Asteroid& a )
    {
        os << dynamic_cast<const ImpactBody&>(a)
           << endl
           << "debris index: " << a.debrisIndex ;
    
        return os;
    }
    
    istream& operator >> ( istream& is, Asteroid& a )
    {
        is >> dynamic_cast<ImpactBody&>( a );
    
        cout << "Enter debris index >> ";
        getline( is, a.debrisIndex );
    
        return is;
    }
    
    ofstream& operator << ( ofstream& os, const Asteroid& a )
    {
        os << 'A' << endl
           << static_cast<const ImpactBody&>(a)
           << a.debrisIndex << endl;
    
        return os;
    
    }
    
    ifstream& operator >> ( ifstream& is, Asteroid& a )
    {
        is >> dynamic_cast<ImpactBody&>( a );
        getline( is, a.debrisIndex );
    
        return is;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    Code:
    cout.operator("incorrect hours entered. Please try again.");
    What are you trying to do here? Shouldn't this just be a normal cout << "incorrect hours entered. Please try again.";

    If you're trying to output the asteroid in the empty spaces, just use:
    Code:
    cout << *this;

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    5
    omg ... my bad ... thats quite embarassing ... thanks dude! ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. Friend func. and overloaded >> and <<
    By Kheila in forum C++ Programming
    Replies: 5
    Last Post: 12-02-2005, 12:14 AM
  3. overloaded >> operator problem
    By quizkiwi in forum C++ Programming
    Replies: 7
    Last Post: 07-19-2005, 03:27 PM
  4. Overloaded >>
    By alphaoide in forum C++ Programming
    Replies: 2
    Last Post: 04-17-2004, 12:27 AM
  5. overloaded on overloads
    By emceedee in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2003, 01:14 AM

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