Operator issues with cout
        Posted  
        
            by BSchlinker
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by BSchlinker
        
        
        
        Published on 2010-04-29T06:30:56Z
        Indexed on 
            2010/04/29
            6:37 UTC
        
        
        Read the original article
        Hit count: 456
        
I have a simple package class which is overloaded so I can output package data simply with cout << packagename. I also have two data types, name which is a string and shipping cost with a double.
protected:
    string name;
    string address;
    double weight;
    double shippingcost;
ostream &operator<<( ostream &output, const Package &package )
{
    output << "Package Information ---------------";
    output << "Recipient: " << package.name << endl;
    output << "Shipping Cost (including any applicable fees): " << package.shippingcost;
The problem is occurring with the 4th line (output << "Recipient:...). I'm receiving the error "no operator "<<" matches these operands". However, line 5 is fine.
I'm guessing this has to do with the data type being a string for the package name. Any ideas?
© Stack Overflow or respective owner